When I register the new user the response that I get is a jwt
token,I store that token in a local storage
of Ionic2.
Then when I login with the same user, I again received that token in response,So when the user gets logged in the next page appears which makes a get
call to load the data for authorized user,which requires token to get authorized(here is the problem I am facing).So the get
call displays an error of status401 unauthorized
.
Here is my server side code to get
the call in the routes.
Server.js
var contactControllers = require('./controllers/contact');
var express = require('express');
var passportService = require('./config/passport');
var passport = require('passport');
var requireAuth = passport.authenticate('jwt', { session: false }),
module.exports = function (app) {
var contactRoutes = express.Router();
app.use('/api/contacts', contactRoutes);
contactRoutes.get('/',requireAuth, function(req,res){
console.log('inside get route of contacts');
contactControllers.getContacts(req,res)});
}
Please help!
via Aditya Jain
No comments:
Post a Comment