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

2022 ж. 14 Қаң.
18 573 Рет қаралды

Enjoying my videos? Sign up for more content here: www.coopercodes.com/
📩 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/coopercodesmen...
Apollo Server Setup: github.com/cooperlappenbusch/...
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

Пікірлер
  • Your explanation is flawless👏

    @melroy36@melroy362 жыл бұрын
  • Underrated channel !!! A genius explanation...

    @rajukadel1007@rajukadel10072 жыл бұрын
  • Dude I was looking for a quick tutorial and you were excellent. You just won a new subscriber. Keep up the good work!

    @hyacinthehamon@hyacinthehamon Жыл бұрын
    • Always appreciate comments like these! Thank you so much for watching (and subscribing)!

      @CooperCodes@CooperCodes Жыл бұрын
    • @@CooperCodes P.S. you should release a video on the auth middleware :)

      @hyacinthehamon@hyacinthehamon Жыл бұрын
    • @@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!

      @r-moncala1976@r-moncala19764 ай бұрын
  • Very good tutorial, thanks from France !

    @wk118@wk118 Жыл бұрын
  • Very detailed and well explained. Thank you

    @hamzahahmad1670@hamzahahmad16702 жыл бұрын
    • 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?

      @mirko3092@mirko30927 ай бұрын
  • 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!

    @rezade5960@rezade59602 жыл бұрын
    • 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!

      @CooperCodes@CooperCodes2 жыл бұрын
  • Thanks, Men you helped me pass my interview

    @thewilliamndubuisi@thewilliamndubuisi7 ай бұрын
    • Really? Where do you Work mate? What did they ask you? Missing a lot of info of usage and the update version v4 aswell

      @mirko3092@mirko30927 ай бұрын
  • 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?

    @juliensebag1547@juliensebag1547 Жыл бұрын
  • 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.

    @tudor14@tudor14 Жыл бұрын
    • 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.

      @CooperCodes@CooperCodes Жыл бұрын
    • There's cookies. header authorization (bearer token) , and specific middleware function to check userRole and userPermission.

      @somerandomchannel382@somerandomchannel382 Жыл бұрын
    • Also looking for this info.

      @rawrbearmedia1426@rawrbearmedia1426 Жыл бұрын
    • 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!

      @benaffermick1796@benaffermick1796 Жыл бұрын
    • @@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.

      @rawrbearmedia1426@rawrbearmedia1426 Жыл бұрын
  • This channel is a sleeper, god you teach so well

    @estrenhus6166@estrenhus61662 жыл бұрын
  • 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.

    @userUndefined404@userUndefined4042 жыл бұрын
    • No problem! Thanks for watching.

      @CooperCodes@CooperCodes2 жыл бұрын
  • 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

    @itmax77@itmax77 Жыл бұрын
  • Where to pass that verifytoken middleware to verify token

    @editingtuto1.011@editingtuto1.011 Жыл бұрын
  • 👏👏👏

    @camilovillarduque2801@camilovillarduque2801 Жыл бұрын
  • This is AWESOME!! U are the MAAAN!! LIKE AND SUB

    @vr4836@vr48362 жыл бұрын
  • the frontend part with verification would be super helpful

    @MB-fc9nd@MB-fc9nd2 жыл бұрын
    • It will be uploaded tonight! It uses React context and Apollo client.

      @CooperCodes@CooperCodes2 жыл бұрын
    • @@CooperCodes thank you

      @MB-fc9nd@MB-fc9nd2 жыл бұрын
  • You have not shown the cookie stuffs which is actually necessary.

    @sowmocoding5740@sowmocoding57406 ай бұрын
  • With help of UseAuth context. And useLocalstorage,

    @rmt0858@rmt08582 жыл бұрын
  • 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 :)

    @rawrbearmedia1426@rawrbearmedia1426 Жыл бұрын
    • 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 :)

      @CooperCodes@CooperCodes Жыл бұрын
    • @@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!

      @rawrbearmedia1426@rawrbearmedia1426 Жыл бұрын
    • 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.

      @CooperCodes@CooperCodes Жыл бұрын
    • @@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

      @rawrbearmedia1426@rawrbearmedia1426 Жыл бұрын
    • 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

      @CooperCodes@CooperCodes Жыл бұрын
  • 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" :/

    @gustavomonte6672@gustavomonte6672 Жыл бұрын
    • 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

      @szachgr43@szachgr43 Жыл бұрын
  • Go look at where ? Where is the video link ? Can you share ? Please provide full information 2:13

    @digiartpassion8513@digiartpassion85132 жыл бұрын
    • kzhead.info/sun/dp1yobCPrGl6fok/bejne.html

      @digiartpassion8513@digiartpassion85132 жыл бұрын
    • My bad, I will edit the description soon.

      @CooperCodes@CooperCodes2 жыл бұрын
  • token for 2h its hard.... and stupid

    @user-sq3nn5wq3z@user-sq3nn5wq3z2 жыл бұрын
  • your github is outdated

    @Dracometeor562@Dracometeor562 Жыл бұрын
KZhead