At 30:10, before the deserializeUser function was defined, it seems like request.user was able to successfully able to be logged to the console. I'm a bit confused though - wasn't the point of deserializeUser to be able to set (and later access) this property on the request object?
Solved my issue! Went to the documentation and saw this: "By default, when authentication succeeds, the req.user property is set to the authenticated user, a login session is established, and the next function in the stack is called." And later... "When the session is authenticated, Passport will call the deserializeUser function, which in the above example is yielding the previously stored user ID, username, and picture. The req.user property is then set to the yielded information." TLDR: the strategy's verify function sets the req.user by default first once authenticated, and then the deserialize function sets it to whatever you specifiy (if the function has been written). I should've said this earlier too but thank you for your videos Anson! They're clear and easy to understand - this was just my own misunderstanding.
It's probably a dumb question but, in the 'discord-strategy.mjs' file, in line 6 - where we are serializing the User by passing the user ID in the done function, shouldn't it be 'user._id' instead of 'user.id' ? We are using the Saved User from MongoDB - which should have '_id' and not 'id' as the variable, right ?
Anson, i'm stuck in this for 3 days straight, almost tried any different ways including dotenv file, old fashioned require and... but i keep facing this error of failed to obtain access token, is there any advice you might provide me, Maestro?
So now I want to use both local and OAuth2, but there are conflicts between the local-strategies and my google-strategies files. I've splited the api route of google into a new file and only import the google-strategies, but it keeps using the Deserial of the local-strategies file. How can I solve this? Thank you.
Did you resolve this? Having the same issue, although with Discord OAuth 2 EDIT: Just use the same serialization and deserialization methods for both strategies. This video calls them on the file where a strategy is defined, but you can call them anywhere.
Ansen, i face error of obtain access token, i did exactly as you said, by the minute of 18. But i can't connect my redirect url. You sure there's nothing wrong with your code?
i followed your video of express series all up to this point and it's impressive. i would like to thank you for creating this series. after trying it myself, i got a few question that i don't understand in this video. 1) it's using discord auth strategy. the user did logged in successfully and the cookies was set alongside the session generation. but when i try to access auth url manually let say "/api/auth/discord" it will redirect me to the discord auth page even i have valid cookie set. that's also happen when i access "/api/auth/discord/redirect". i don't know is this expected behavior or an error in my code, but i added a function middleware that checking user if it's authenticated then redirect them somewhere else, preventing them to re-auth when accessing the auth url manually. is what am i doing is correct or something is missing that caused this? 2) are these configurations up to this point in this tutorial is enough for production purpose or any advice (or video you got) i could follow? thank you 😇
At 30:10, before the deserializeUser function was defined, it seems like request.user was able to successfully able to be logged to the console. I'm a bit confused though - wasn't the point of deserializeUser to be able to set (and later access) this property on the request object?
Solved my issue! Went to the documentation and saw this: "By default, when authentication succeeds, the req.user property is set to the authenticated user, a login session is established, and the next function in the stack is called." And later... "When the session is authenticated, Passport will call the deserializeUser function, which in the above example is yielding the previously stored user ID, username, and picture. The req.user property is then set to the yielded information." TLDR: the strategy's verify function sets the req.user by default first once authenticated, and then the deserialize function sets it to whatever you specifiy (if the function has been written). I should've said this earlier too but thank you for your videos Anson! They're clear and easy to understand - this was just my own misunderstanding.
Very cool video,please make more such tuts
It's probably a dumb question but, in the 'discord-strategy.mjs' file, in line 6 - where we are serializing the User by passing the user ID in the done function, shouldn't it be 'user._id' instead of 'user.id' ?
We are using the Saved User from MongoDB - which should have '_id' and not 'id' as the variable, right ?
how that id property coming to the user bro🤔
user.id is the ID of the User document saved in MongoDB. You can also reference it as user._id, you get the same value.
Ok thanks bro😅
Brutha, i got an error of failed to obtain access token. What can i do?
Are your clientID and clientSecret correct? Could be that, or maybe a misconfiguration w the callbackURL
can u make google auth?
Anson, i'm stuck in this for 3 days straight, almost tried any different ways including dotenv file, old fashioned require and... but i keep facing this error of failed to obtain access token, is there any advice you might provide me, Maestro?
So now I want to use both local and OAuth2, but there are conflicts between the local-strategies and my google-strategies files. I've splited the api route of google into a new file and only import the google-strategies, but it keeps using the Deserial of the local-strategies file. How can I solve this? Thank you.
Did you resolve this? Having the same issue, although with Discord OAuth 2
EDIT: Just use the same serialization and deserialization methods for both strategies. This video calls them on the file where a strategy is defined, but you can call them anywhere.
@@televisaoassassina9822 I used Firebase instead of OAuth2. It's not optimal, but Firebase kinda fits my needs.
Ansen, i face error of obtain access token, i did exactly as you said, by the minute of 18. But i can't connect my redirect url. You sure there's nothing wrong with your code?
i followed your video of express series all up to this point and it's impressive. i would like to thank you for creating this series.
after trying it myself, i got a few question that i don't understand in this video.
1) it's using discord auth strategy. the user did logged in successfully and the cookies was set alongside the session generation. but when i try to access auth url manually let say "/api/auth/discord" it will redirect me to the discord auth page even i have valid cookie set. that's also happen when i access "/api/auth/discord/redirect". i don't know is this expected behavior or an error in my code, but i added a function middleware that checking user if it's authenticated then redirect them somewhere else, preventing them to re-auth when accessing the auth url manually. is what am i doing is correct or something is missing that caused this?
2) are these configurations up to this point in this tutorial is enough for production purpose or any advice (or video you got) i could follow?
thank you 😇
Anson, are you really going to fail me after all? I thought tú eras un gran maestro, pero ...