Express JS #19 - OAuth2

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

ความคิดเห็น • 11

  • @ultimatesonic7
    @ultimatesonic7 6 หลายเดือนก่อน +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 6 หลายเดือนก่อน

      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.

  • @ArijitBanerjeeArley
    @ArijitBanerjeeArley 8 หลายเดือนก่อน +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 7 หลายเดือนก่อน

      how that id property coming to the user bro🤔

    • @ansonthedev
      @ansonthedev  7 หลายเดือนก่อน +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 7 หลายเดือนก่อน

      Ok thanks bro😅

  • @springrice
    @springrice 6 หลายเดือนก่อน +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 23 วันที่ผ่านมา

      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 23 วันที่ผ่านมา

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

  • @aeshyx
    @aeshyx 5 หลายเดือนก่อน

    can u make google auth?