User Authentication with Apollo Server V3, MongoDB, GraphQL, and JWT

Поделиться
HTML-код
  • Опубликовано: 16 окт 2024
  • Enjoying my videos? Sign up for more content here: www.coopercode...
    📩 Join codeLetter by Cooper Codes, the 3 minute tech newsletter: thecodeletter.com
    Interested in a 1:1 mentorship with me? Jumpstart your career at www.rebrand.ly...
    Apollo Server Setup: github.com/coo...
    Video Mentioned at 2:13 : • Apollo Server / MongoD...
    Hey it's Cooper, make sure to subscribe for more full stack development content in the future!
    In this video we do an in depth setup of creating an Apollo Server capable of registering / logging in users. This login and register functionality can get tricky at times, but hopefully this video provides a great starting point for creating the backend to your applications. Subscribe for the future video I plan on making where we create a React application that handles the users tokens, allowing "user only" functionality (only allow people to do things if they have a token for example).
    Want to support me? Purchase on Amazon with my link here: amzn.to/3Q4h3Pb
    Enjoying my content? Feel free to support me on Patreon / coopercodes
    Business inquiry? Email thecoopercodes@gmail.com

Комментарии • 49

  • @hyacinthehamon
    @hyacinthehamon 2 года назад +2

    Dude I was looking for a quick tutorial and you were excellent. You just won a new subscriber. Keep up the good work!

    • @CooperCodes
      @CooperCodes  2 года назад +2

      Always appreciate comments like these! Thank you so much for watching (and subscribing)!

    • @hyacinthehamon
      @hyacinthehamon 2 года назад

      @@CooperCodes P.S. you should release a video on the auth middleware :)

    • @r-moncala1976
      @r-moncala1976 9 месяцев назад

      @@CooperCodes Hi Cooper, I just have a question. is there a way that the token will be sent to the user as a cookie? thanks!

  • @rohandatta978
    @rohandatta978 4 месяца назад

    Hey Cooper Codes! Excellent tutorial, I followed it to the end. I have one question though, you hadn't gone over how a user would log out. I was wondering if you could give a brief summary of the process that needs to happen for the user to log out. I can figure out the user deletion part as that isn't very difficult, but for logging out, how does it work for the JWT token?

  • @williamNshorts
    @williamNshorts Год назад +1

    Thanks, Men
    you helped me pass my interview

    • @mirko3092
      @mirko3092 Год назад

      Really? Where do you Work mate? What did they ask you? Missing a lot of info of usage and the update version v4 aswell

  • @tudor14
    @tudor14 2 года назад +10

    One thing I've noticed with pretty much all of these types of tutorials, is the failure to mention how to protect specific resolvers, due to the nuances of using the context argument. An example being, you have a news site, all users can access the index page, but only specific users that are logged in can access individual articles. So you want to protect the individual news article resolver. While these videos are helpful, 'protecting' routes is equally important as demonstrating how to set up user authentication. So please, if you have the time and knowledge, you'd be doing a great service to update this video to include that. Thanks.

    • @CooperCodes
      @CooperCodes  2 года назад +6

      I will make a video on protected routes with Apollo Server soon, for this tutorial I wanted the focus to be more on the JWT store and Apollo Server GraphQL API setup just for login / register. User Auth is a pretty complicated subject, as you seem to understand well, so it can be difficult to make a video covering everything all at once. Thank you for your comment and support.

    • @somerandomchannel382
      @somerandomchannel382 2 года назад

      There's cookies. header authorization (bearer token) , and specific middleware function to check userRole and userPermission.

    • @rawrbearmedia1426
      @rawrbearmedia1426 2 года назад

      Also looking for this info.

    • @benaffermick1796
      @benaffermick1796 2 года назад

      Can confirm - this is the ENTIRE point of user authentication. Deciding who can access what, based on who they are. If you can't demonstrate how to protect resources from unauthorized access, then the video is useless!

    • @rawrbearmedia1426
      @rawrbearmedia1426 2 года назад +1

      @@benaffermick1796 Just found a video on his channel that might be the solution but I'm too tired to go into it tonight. Take a look at "React Login with Apollo Server, Context, JWT (Apollo Server Tutorial)" it seems like it continues on from this one. Might be what we're looking for.

  • @rajukadel1007
    @rajukadel1007 2 года назад

    Underrated channel !!! A genius explanation...

  • @wk118
    @wk118 2 года назад

    Very good tutorial, thanks from France !

  • @itmax77
    @itmax77 Год назад +1

    why you store jwt token in DB with user? the main idea of jwt is that you can easily check if token provided by user is legit and you don't need to store it and update in DB

  • @malfoy2797
    @malfoy2797 2 года назад

    Your explanation is flawless👏

  • @rezade5960
    @rezade5960 2 года назад

    Thanks mate! was stuck on a very bad error from a week and just figured that I needed to add _ before doc haha, saw some old videos and no one did this maybe it was after the updated anyways, Thanks! Great video!

    • @CooperCodes
      @CooperCodes  2 года назад +2

      Yeah the _doc stuff is strange, the Apollo server documentation can be helpful but there are weird intricacies. Thanks for the comment and your support!

  • @estrenhus6166
    @estrenhus6166 2 года назад

    This channel is a sleeper, god you teach so well

  • @hamzahahmad1670
    @hamzahahmad1670 2 года назад +1

    Very detailed and well explained. Thank you

    • @mirko3092
      @mirko3092 Год назад

      What are you talking about? I mean where is using the auth file created? In login is creating a new token ... So that auth file with the checking of is new is not used or am I wrong?

  • @juliensebag1547
    @juliensebag1547 2 года назад

    Thanks a lot for your amazing video! Just a question, at some point you add an auth middleware, how can we use it in this project?

  • @MB-fc9nd
    @MB-fc9nd 2 года назад

    the frontend part with verification would be super helpful

    • @CooperCodes
      @CooperCodes  2 года назад +2

      It will be uploaded tonight! It uses React context and Apollo client.

    • @MB-fc9nd
      @MB-fc9nd 2 года назад

      @@CooperCodes thank you

  • @gustavomonte6672
    @gustavomonte6672 2 года назад

    Mine keeps giving "throw new Error(`${typeName}.${fieldName} defined in resolvers, but not in schema`); Error: Mutation.Query defined in resolvers, but not in schema" :/

    • @szachgr43
      @szachgr43 Год назад

      that means you, created a resolver but there is nothing related to that resolver in the schema. CHeck if you didn't do a type in schema

  • @sowmocoding5740
    @sowmocoding5740 11 месяцев назад

    You have not shown the cookie stuffs which is actually necessary.

  • @editingtuto1.011
    @editingtuto1.011 Год назад

    Where to pass that verifytoken middleware to verify token

  • @digiartpassion8513
    @digiartpassion8513 2 года назад

    Go look at where ? Where is the video link ? Can you share ? Please provide full information 2:13

    • @digiartpassion8513
      @digiartpassion8513 2 года назад

      ruclips.net/video/C99qLWu7DKQ/видео.html

    • @CooperCodes
      @CooperCodes  2 года назад

      My bad, I will edit the description soon.

  • @rawrbearmedia1426
    @rawrbearmedia1426 2 года назад

    Great series, I hope there's more to come. I'd love to know how to do something like a simple blog. I have users, I have posts.. I have users able to log in (from following this video) but I don't know how to assign a user to an article. How do you keep the user logged in and say "ok, you are user MARIO and you have permission to write posts. When you submit this post you will be the author". I can't find how to make this work. Any help would be great :)

    • @CooperCodes
      @CooperCodes  2 года назад +1

      For sure going to make a video along these lines, working on some full stack projects to showcase soon. Thanks for hoping there is more to come, I try my best to make content thats approachable and educates :)

    • @rawrbearmedia1426
      @rawrbearmedia1426 2 года назад

      @@CooperCodes I have to watch your videos a few times to really understand what's going on but your content is the most useful I have seen on the subjects of Apollo and full stack apps. I'm looking forward to your new projects! Thanks for the videos, bro!

    • @CooperCodes
      @CooperCodes  2 года назад +1

      You are very welcome! I am curious, is there anything in particular that makes you feel the need to rewatch the videos in order to understand what's going on? I am always looking to continue making the best content on these subjects so I won't take anything personally :) , just looking to make my videos better every time. My pacing is quite fast for the topics covered, so I'm curious if the pace felt a bit too much for you.

    • @rawrbearmedia1426
      @rawrbearmedia1426 2 года назад

      @@CooperCodes The pace is blazing fast lol. I've been coding for years but when it comes to new concepts, I like to know all the details so I put the speed to 0.75 and watch you in slow mode lol.
      As an example from your other video (the one with React), I followed everything and got all the login and user registration stuff working. But.. When I go to make an Article setup so that I can create articles and have the "author" be the logged in user, it breaks. I don't know why it breaks, it has something to do with the context.login() stuff I think but I don't understand how each part interacts with the next part.
      For me to learn how all this works, each section would need to be broken down into chunks, maybe with an example of how/why the code is the way it is. I don't know if your videos are intended for people new to Apollo and Graphql so I figured it was just a "me" problem and other people are the target audience.
      It's hard to explain in a YT comment.. I have to watch multiple times to understand the theory behind "why" the code works so that I can go build my own things and know how to code each part.
      I know a lot of people like the speed run type of thing, they just want the code to work and be done with it but I need to understand all the details so I can comfortably go code my own apps and whatever.
      If you have a Discord or some kind of contact info, I'd be happy to explain more and maybe you could point out what I screwed up XD

    • @CooperCodes
      @CooperCodes  2 года назад

      The current content is def in at an intermediate level which I may change for videos in the future. I envision an audience of people that want to see how “everything works together” and not “how everything works” if that makes sense. I will definitely make some changes to this though, as I’m realizing that some of the parts of the video can be a bit fast (way too fast). I appreciate the constructive feedback and I am definitely looking to the future in making my videos as good as possible, especially when getting into more advanced concepts.
      My goal is to definitely allow people to code their own apps, so I’m going to keep that thinking as an emphasis in the future. Possibly incorporating examples for different use cases, or saying things like “if you wanted to add another variable to your context, it could look like this”.
      I am also planning on creating more content which is friendly to both beginners and intermediates.
      Thanks again appreciate the feedback

  • @vr4836
    @vr4836 2 года назад +1

    This is AWESOME!! U are the MAAAN!!
    LIKE AND SUB

  • @camilovillarduque2801
    @camilovillarduque2801 2 года назад

    👏👏👏

  • @rmt0858
    @rmt0858 2 года назад

    With help of UseAuth context. And useLocalstorage,

  • @userUndefined404
    @userUndefined404 2 года назад

    Cara faz muito tempo que estou procurando um conteúdo desse tipo. Obrigado.
    Guy, It's been a long time such contents about this, thank you for that.

    • @CooperCodes
      @CooperCodes  2 года назад +1

      No problem! Thanks for watching.

  • @HelloGoodbye-f6q
    @HelloGoodbye-f6q 2 года назад

    token for 2h its hard.... and stupid

  • @Dracometeor562
    @Dracometeor562 2 года назад

    your github is outdated