Currently I have the following configuration for passport. Here, each login request is coming from /login/students. The getUserById function finds the user from a STUDENT table stored in database. But login requests can also come from /login/instructors, and in that case I would like to find users from INSTRUCTORS table. But currently there is no way to check the incoming route's name. How would I know that from which route my login request is coming from? Any help appreciated :)
const initialize = (passport) => {
passport.use(new LocalStrategy({ usernameField: 'username', passwordField: 'password' }, authenticateUser));
passport.serializeUser((user, done) => done(null, user.ID));
passport.deserializeUser(async (id, done) => {
const user = await getUserById(id);
done(null, user);
});
};
Code for login router:
router
.route('/login/students')
.post(
checkAuth.not, //login only if user is not in current session
passport.authenticate('local', {
successRedirect: '/home/students',
failureRedirect: '/login/students',
})
);