skip to Main Content

I am creating a general chat application with react, and am stuck while trying to authenticate a user. The axios post request raises a 500 error that I cannot track anywhere. When I put in correct authentication for a user, it says that the password was correct (aka, the user and password was found in the database), but then I believe the serialization/deserialization of the user is messing up somewhere but again, I can’t figure it out.

I’ve tried debugging and logging, it fetches the user properly, un-hashes the password correctly. heres a link to a github repo,
https://github.com/Macpickle/Chatroom-REACT

any help is appreciated, i feel it is something small but again stumping me. thanks.

2

Answers


  1. Chosen as BEST ANSWER

    fixed the issue on my own, figured out to move the external router below the passport initialization as it is required in the router to authenticate a user. i appreciate your guy's help very much. thank you.


  2. I certainly can’t say but in your code

    //initialize passport
     initpassport(
        passport,
        async username => await User.findOne({ username: username }),
        async id => await User.findOne({ _id: id })
     );
    
     app.use(passport.initialize());
     app.use(passport.session());
    

    this is what you are using, i want you to write those app.use() part above initpassport like this :

    app.use(passport.initialize());
    app.use(passport.session());
    
    //initialize passport
    initpassport(
        passport,
        async username => await User.findOne({ username: username }),
        async id => await User.findOne({ _id: id })
    );
    

    Try that and let me know if it works or not!
    We’ll try some other things after that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search