angularjs - Redirecting to profile page before login in node.js using passport.js -
i have 2 pages http://localhost:3000/pages/auth/login
, http://localhost:3000/pages/profile
.
when give login details goes profile page in address bar directly give /pages/profile.
i want comes login page. authentication using passport-local authentication.
all passport store session on server side. on front-end need make calls end see if session still active. front-end knows nothing on back-end unless type of response back-end.
this assuming using expressjs passport.js
you need create function handle login checks
function isloggedin(req, res, next) { // if user authenticated in session, carry on if (req.isauthenticated()) return next(); // if aren't redirect them home page res.redirect('/pages/auth/login'); }
your backend route should handle frontend when sends check request
app.get('/pages/profile', isloggedin, function(req, res) { // send them profile page });
Comments
Post a Comment