Authentication Token

//Client export class JwtInterceptor implements HttpInterceptor { constructor(public auth: AuthenticateService) {} intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { let token = this.auth.getToken(); request = request.clone({ headers: request.headers.set(`header`,token) }); console.log("REQ",token) return next.handle(request); } } //Server module.exports.authToken = function(req, res, next){ var token = req.headers['header'] if(token){ jwt.verify(token, secret, function(err,decoded){ if(err){ console.log(err) res.json({ message: "Token is invalid" }); }else{ req.decoded = decoded next(); } }); }else{ res.json({ success: false, message: 'No token provided' }); } } module.exports.tokenDecode = function(req, res) { console.log("Getting decoded.....", req.decoded); return res.send(req.decoded); // Return the token acquired from middleware };
If I console log the header it shows me the token, but it is not getting read.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.