andre
andre

Reputation: 7249

Can I return my own custom token base authentication in node js

I am using node-js restify. While signing a user up server.head('/signup', function (req, res, next) I generate a custom token.

token = ***
res.set('token', token);
res.send();

I am trying to send the token back but I can't find any documentation on how this is done. How do I send a token in a header response?

Upvotes: 0

Views: 90

Answers (1)

Medet Tleukabiluly
Medet Tleukabiluly

Reputation: 11940

Check this working sample

var express = require('express');
var app = express();

app.head('/token', function(req, res, next){
   res.writeHead (200, {'token': Math.random()});
   res.end();
});

app.listen(3001);

And the POSTMAN request enter image description here

As you can see everything works as expected, the response body is always empty, but header has token field

Upvotes: 1

Related Questions