Express JS #19 - OAuth2
Vložit
- čas přidán 7. 09. 2024
- Watch the full tutorial here: • Express JS Full Course
Code Repository: github.com/stu...
Support the Channel:
Become a Member: www.youtube.co...
Become a Patreon: / stuyy
Buy me a Coffee: ko-fi.com/anson
Donate on Streamlabs: streamlabs.com...
Donate on PayPal: paypal.me/anso...
Connect with me:
Twitter: / ansonthedev
Discord: / discord
GitHub: github.com/stuyy
Twitch: / stuy
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.
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 ?
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😅
can u make google auth?