GraphQL/JWT Speed Run with Refresh Tokens

  Рет қаралды 16,780

Jack Herrington

Jack Herrington

Күн бұрын

Пікірлер: 68
@Deliverant
@Deliverant 2 жыл бұрын
Great stuff as usual. Could you make a video on the new features of next.js version 12? Thanks
@DioArsya
@DioArsya 2 жыл бұрын
Hey great video as always, but one thing that I always concern is the vscode zoom. It's great bcs you zooming in the editor so we can see it better on smaller devices, but I think it could be zoomed out once so it won't too big and we can see some other codes. Thank youu!
@dars1816
@dars1816 2 жыл бұрын
Can you make a video comparing JWT and Sessions (redis)?
@paulomirandaarias9544
@paulomirandaarias9544 Жыл бұрын
Very nice video. With Apollo Client its possible to do the same with onErrorLink
@vin5718
@vin5718 2 жыл бұрын
I implemented JWT Authentication on my last project and I found a very useful guide about using two JWT token for implementing access and refresh token (with different secret) with the access token is stored only in memory and refresh token on the cookie. I found this approach really neat as I can keep my server stateless and authentication works across multiple servers. However, I would like to know what’s your recommendations on handling refresh token?
@jherr
@jherr 2 жыл бұрын
I think there are a lot of different ways to handle it. The method I've used here sounds pretty close to what you are saying. I do hold the lookup of refresh tokens on the server, but that could easily be swapped out to keep it stateless. There are some security concerns around refresh tokens though, so you'll want to make sure that your approach is secure enough for your application before you go for it.
@vin5718
@vin5718 2 жыл бұрын
@@jherr Ok noted
@mostafahamid9479
@mostafahamid9479 2 жыл бұрын
I was about to search for auth using graphql already and suddenly, a notification just poped up with this new video. :)
@luar4165
@luar4165 7 ай бұрын
any chance this would be updated with Apollo-server 4? Thanks anyway for your always awesome content.
@martinholecekmax
@martinholecekmax Жыл бұрын
This is a great video. I wish I could have seen it a couple of months ago when I was trying to figure out how to do this. It's really tricky to get all the pieces to work together, especially the JWT token part. I'm glad you made this video. Thank you 👍
@adamtak3128
@adamtak3128 2 жыл бұрын
I appreciate that you want to make the code easily readable but it's way too zoomed in. Thanks for the lesson!
@kamrannamazov1868
@kamrannamazov1868 Жыл бұрын
thanks for the video. What if i use not axios for requests, only graphql mutations and queries. I think in this case interceptor is not a solution. Is there any implementation specifically for the graphql and refresh token?
@imsantoshsingh
@imsantoshsingh 2 жыл бұрын
U r the best
@faizansayyed3047
@faizansayyed3047 2 жыл бұрын
Its just so much valuable information you share each time in most of your videos !! Thank you Jack🙂
@jerrynusatrip947
@jerrynusatrip947 2 жыл бұрын
Awesome Jack, Very simple, but powerful. All the best.!! Thanks
@davidhavl
@davidhavl Жыл бұрын
Thanks!
@Billy_98
@Billy_98 2 жыл бұрын
Brilliant.Thank you!
@iizMerk
@iizMerk 2 жыл бұрын
Nice video jack! It will be nice to see with URQL than react-query
@raymondmichael4987
@raymondmichael4987 2 жыл бұрын
I don't know, how you get those codes populated, like when you created a users files,or you skip some parts 😳
@brimmedHat
@brimmedHat 2 жыл бұрын
bravo!
@Skia_
@Skia_ 2 жыл бұрын
Awesome tutorial, It would be great if you could make a tutorial on how to implement an optimistic UI mechanism using only React hooks
@StringSwoosh
@StringSwoosh Жыл бұрын
Nice vid! Can you also use apollo client instead of axios? Is there any benefit to using apollo client or axios?
@lydstyl
@lydstyl Жыл бұрын
Why refreshing token when we can make the token live 20 hours ? Is it unsecure ?
@ashishshetty1926
@ashishshetty1926 2 жыл бұрын
is saving the token in localstorage or session a bad practice ? I believe you are storing it global state. Enjoyed your video, keep it coming !
@jherr
@jherr 2 жыл бұрын
I don't think that's a problem.
@karsongrady
@karsongrady 2 жыл бұрын
Great stuff. Thank you so much for breaking it down the way you did
@mani8586
@mani8586 2 жыл бұрын
Perfect...👍🎃
@SeanCassiere
@SeanCassiere 2 жыл бұрын
Had absolutely no idea that axios had a built in method for calling a refresh token... Quite abit of useful info was covered in this one. Will definitely have to pull down the repo and go through it.
@jr-hp7er
@jr-hp7er 2 жыл бұрын
Awesome Jack, Thanks alot
@odalisvalencia7288
@odalisvalencia7288 2 жыл бұрын
Increible tutorial, Te admiro. te ganaste un like
@martinsonuoha
@martinsonuoha 2 жыл бұрын
And Jack drops another one
@PeterJaffray
@PeterJaffray 2 жыл бұрын
After going through this tutorial a dozen times (amazing btw) I think I finally grasped how the GUID in the refresh token becomes the marker for the user name. That part was really tricky. refreshTokens[token.data] = name. Should we also use two different secrets for the Refresh Token and the Auth Token?
@jherr
@jherr 2 жыл бұрын
Yes!
@PeterJaffray
@PeterJaffray 2 жыл бұрын
I got in a refresh loop but realized that the map refreshtokens was lost on restart so I added a response that if refreshTokens didn't contain user then return null. This was a really rewarding project 🤙
@MrPlaiedes
@MrPlaiedes 2 жыл бұрын
No one else calls it J W T?
@RicardoValero95
@RicardoValero95 2 жыл бұрын
Great video! Have you considered expanding your go-to todo example to include subscriptions? Or maybe change to a chat app example hehe. Just pointing out subscriptions are treated as second class. Another idea: webRTC? Either way thanks for this very insightful video!
@jherr
@jherr 2 жыл бұрын
Oh, subscriptions are definitely not second class to me. I'm a huge fan of all things pub/sub, GraphQL subscriptions, Firebase, etc. all of that. I did end up turning a todo app into a chat app in a recent video, FWIW. Maybe that's what you were alluding to?
@RicardoValero95
@RicardoValero95 2 жыл бұрын
@@jherr what? yes! I tend to watch all your graphql and ts related videos. guess I missed one or two. can't wait to watch it. thanks!
@ATTI0822
@ATTI0822 2 жыл бұрын
What happens if the client initiates parallel requests? (for example, when somebody opens a modal, this modal needs data from backend to fill 5 dropdowns). 5 requests start to fly out, just suppose that the 3rd, 4th, 5th come back with error 401, token expired. Will axios handle this situation correctly? Calls the refresh endpoint, then retries for these 3 endpoints again with the current and valid access token? I'm just courious because some weeks ago I encountered this issue inside Angular interceptor. Rxjs switchMap and the semaphor principle handled this situation correctly. Do you have experiences with this situation with axios?
@jherr
@jherr 2 жыл бұрын
It's unlikely that the code as-is will block the four requests that follow after the first one fails. My hunch is that you'll get five 401s, that this will cause five subsequent refreshes, five token updates and five more requests at the very least. There might be some mitigation by the JWT the second time around being the same as the first after subsequent refreshes. But that would probably just help with the React update cycle. FWIW, I think the primary issue here isn't with this patter per-se but more in making five simultaneous calls in the first place. You should put a GraphQL aggregation server in the middle there and then make one request with all five queries.
@ATTI0822
@ATTI0822 2 жыл бұрын
@@jherr Yep I agree. Btw great video and explanation, not the easiest topic I'm sure 😅
@jherr
@jherr 2 жыл бұрын
@@ATTI0822 Yeah, the code on this one was about two days to write, which is unusually bad. Lots of stuff around CORS and response codes. Once I got it running it was pretty quick, but ... sheesh... sometimes. Fortunately, it's the kind of thing you get right once and after that you're usually (fingers crossed) pretty set.
@designcoded7585
@designcoded7585 2 жыл бұрын
sir how we can use graphql socketio express together
@jherr
@jherr 2 жыл бұрын
Websockets are just upgraded HTTP connections, so the authentication pattern should work the same pre-upgrade to websocket.
@inversebrah
@inversebrah 2 жыл бұрын
great content as usual
@bernardb2348
@bernardb2348 2 жыл бұрын
Anyone knows why refreshtokens (with an s) is for? Doesn’t that go against the principal if we store tokens in a centralized database ? Edit: in this case it’s and mapped object/ js array but I’m guessing in production it’s a database
@mdwork341
@mdwork341 Жыл бұрын
The screen zoom in too much
@denilsoncosta9837
@denilsoncosta9837 2 жыл бұрын
Amazing video very helpful, i'd like to know, what's the way to implemente authorized routes in this workflow?
@jherr
@jherr 2 жыл бұрын
With GraphQL you check permissions within the resolver to make sure your the current user has access to that particular resolver, or to reduce the data returned from the resolver to just the data for that user.
@denilsoncosta9837
@denilsoncosta9837 2 жыл бұрын
​@@jherr i create a is-logged-in mutation, that verify the refresh token cookie and return the user. it´s a valuable way or there is a better approach? My goal is make the frontend know that the user is logged in without store the data for example in local store.
@jherr
@jherr 2 жыл бұрын
@@denilsoncosta9837 I don't think there is any extra data leak from just returning true or false if you are logged in or not and updating the refresh token.
@denilsoncosta9837
@denilsoncosta9837 2 жыл бұрын
@@jherr thanks!
@nepalcodetv6298
@nepalcodetv6298 2 жыл бұрын
How would you deal with disadvantages like: caching(redis), rate limiting ?
@boot-strapper
@boot-strapper 2 жыл бұрын
off topic question: Do you recommend Happy Valley? I'm looking at buying a house and it seems like you get more for your money over there, but I have lived on the west side for years. Really need like 6 bedrooms...
@jherr
@jherr 2 жыл бұрын
We really enjoy it here. I used to work in the west side (at Nike) and I find that Happy Valley feels more "lived in" and less "cookie cutter" than the west side. IMHO. Six bedrooms is a lot, but there are definitely houses around here that are that big.
@boot-strapper
@boot-strapper 2 жыл бұрын
@@jherr It's not ideal, but im going to be house poor to take care of a couple family members. From the pictures of happy valley I have seen, I agree. I'm just worried about amenities and such. I like good food, which is why I love in portland to begin with!
@jherr
@jherr 2 жыл бұрын
@@boot-strapper The amenities are improving. We have already some good restaurants and that's definitely been improving since we moved here. If we want to go out for a good meal all of SE Portland and all its restaurants are just over the hill. There are great spots in Sellwood, Division, Hawthorne, as well as Oregon City if you go south a little. If you want to chat more interactively about it you can hit me up on DMs on my Discord server, or use Twitter DM. I'd be happy to meet up for lunch or whatever.
@boot-strapper
@boot-strapper 2 жыл бұрын
@@jherr How can I find your discord?
@boot-strapper
@boot-strapper 2 жыл бұрын
@@jherr Nevermind! I found it. I will hop on there one of these days
@sitcomrave
@sitcomrave 2 жыл бұрын
Great explanation but not really a speedrun.
@jherr
@jherr 2 жыл бұрын
Well, in comparison to some of the other JWT related videos I've seen which can run into hours... it's speed-ier.
@lydstyl
@lydstyl Жыл бұрын
@@jherr It is to speed for my little brain but thank your for the video.
@sleepingsaintz
@sleepingsaintz 2 жыл бұрын
Will the refresh token persisits if user closes the tab?
@jherr
@jherr 2 жыл бұрын
You’ll need to get a new JWT but the cookie should persist.
@sleepingsaintz
@sleepingsaintz 2 жыл бұрын
@@jherr Just to confirm, even after closing the tab, the cookie from set-cookie header stays in browser storage, and using that we need to get a new jwt if we open the site in new tab. Am I right?
@jherr
@jherr 2 жыл бұрын
@@sleepingsaintz Not with the code currently as written, you'd have to try to do the refresh first to know if you have a refreshToken and if that fails then force the login.
@sleepingsaintz
@sleepingsaintz 2 жыл бұрын
@@jherr thank you
@limoni0523
@limoni0523 2 жыл бұрын
Connan Obrien lol
Session Vs JWT: The Differences You May Not Know!
7:00
ByteByteGo
Рет қаралды 165 М.
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 51 МЛН
小丑妹妹插队被妈妈教训!#小丑#路飞#家庭#搞笑
00:12
家庭搞笑日记
Рет қаралды 38 МЛН
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 13 МЛН
Ozoda - Lada ( Ko’k jiguli 2 )
06:07
Ozoda
Рет қаралды 15 МЛН
Клиент Apollo GraphQL для React-приложений
44:11
Михаил Непомнящий
Рет қаралды 29 М.
The Hidden Cost Of GraphQL And NodeJS
28:35
ThePrimeTime
Рет қаралды 193 М.
Why is JWT popular?
5:14
ByteByteGo
Рет қаралды 319 М.
Is Your API ACTUALLY Ready for User Traffic?
6:59
Tech Vision
Рет қаралды 100 М.
Mastering React's useEffect
25:20
Jack Herrington
Рет қаралды 174 М.
What are Refresh Tokens?! and...How to Use Them Securely
19:29
Solid + GraphQL = Realtime Magic
33:46
Jack Herrington
Рет қаралды 29 М.
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 51 МЛН