1
I’m having a problem logging in to the blog, the problem is: when trying to log in the first time with a user 0 (without being admin) it keeps loading the page and goes nowhere, but after I click on another tab or reload the page is logged in, only happens if I do this, if I try to log in with an admin user (1) it normally performs the access, I log in and try to log back in user 0 it works correctly. I think it’s a problem with the middleware but I couldn’t find that authentication flaw
An excerpt from the authentication code:
module.exports = {
pAdmin: function(req, res, next){
if(req.isAuthenticated()){
return next();
}
req.flash("error_msg", "Você precisa ser um professor")
res.redirect("/")
}
}
Note: I’m still new.
Does anyone know what might be going on?
1: How is the login being done? Normally we generate a token in the registration and login 2: Are you passing the token correctly? headers:{"Authentication":" token code "} 3: Are you using oq to test your API? Insomnia?
– Serginho junio
I’m using Passport-locals, I’m new, apparently everything is OK with the code, I noticed that the user was logged in but did not move on, as if missing a next(), I did a gambiarra with javascript where I redirect it to the home page, so it "hangs" the next()I believe that for something initial it must be working, but I also know that it is not the right thing to do.
– André Cabral
Javascript, but are you using React-Native, reactjs or others as front? Normally we do nothing within middleware.
– Serginho junio
I’m using the Handlebars
– André Cabral