Express JS #19 - OAuth2

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ • 18

  • @ultimatesonic7
    @ultimatesonic7 8 місяців тому +1

    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?

    • @ultimatesonic7
      @ultimatesonic7 8 місяців тому +2

      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.

  • @janardhanpolle7255
    @janardhanpolle7255 Місяць тому

    Very cool video,please make more such tuts

  • @ArijitBanerjeeArley
    @ArijitBanerjeeArley 9 місяців тому +1

    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 ?

    • @SathishS-y3z
      @SathishS-y3z 9 місяців тому

      how that id property coming to the user bro🤔

    • @ansonthedev
      @ansonthedev  9 місяців тому +1

      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.

    • @SathishS-y3z
      @SathishS-y3z 9 місяців тому

      Ok thanks bro😅

  • @Teacherpleacher
    @Teacherpleacher 24 дні тому +1

    Brutha, i got an error of failed to obtain access token. What can i do?

    • @eved.a
      @eved.a 17 днів тому

      Are your clientID and clientSecret correct? Could be that, or maybe a misconfiguration w the callbackURL

  • @aeshyx
    @aeshyx 7 місяців тому +2

    can u make google auth?

  • @Teacherpleacher
    @Teacherpleacher 23 дні тому

    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?

  • @springrice
    @springrice 8 місяців тому +1

    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.

    • @televisaoassassina9822
      @televisaoassassina9822 2 місяці тому +1

      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.

    • @springrice
      @springrice 2 місяці тому

      @@televisaoassassina9822 I used Firebase instead of OAuth2. It's not optimal, but Firebase kinda fits my needs.

  • @Teacherpleacher
    @Teacherpleacher 23 дні тому

    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?

  • @rickysambora8321
    @rickysambora8321 Місяць тому

    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 😇

  • @Teacherpleacher
    @Teacherpleacher 23 дні тому

    Anson, are you really going to fail me after all? I thought tú eras un gran maestro, pero ...