No video

Securely using JWT on the Edge: Authentication in NextJS Middleware!

  Рет қаралды 38,483

Josh tried coding

Josh tried coding

Жыл бұрын

Handling JWT-based authentication inside of NextJS middleware is super fast, and very useful but can be a bit tricky to implement. Let's look at best practises for implementing JWT auth inside of NextJS middleware, eliminating the need to call a separate API route to handle the JWT authentication. We'll also pass back the JWT from a tRPC backend route back to the client.
⭐ Our startup: wordful.ai
Thanks for watching, have fun implementing JWT-based authentication inside of your NextJS app!

Пікірлер: 57
@hepsko2318
@hepsko2318 Жыл бұрын
Hi, I liked the protected routing using middelware. But what if, for example, we are using an external backend, you would still recommend using this approach, minus the token verification (because that is already happening on the backend)?
@codingwithrendi
@codingwithrendi Ай бұрын
You have saved my life josh :)
@developer_hadi
@developer_hadi Жыл бұрын
Bro please complete the booking system playlist, the idea looks awesome
@raymondmichael4987
@raymondmichael4987 Жыл бұрын
Did he abandoned it already!?😢
@joshtriedcoding
@joshtriedcoding Жыл бұрын
@@raymondmichael4987 Hell nah this series is going on, just not every video right after another :^)
@raymondmichael4987
@raymondmichael4987 Жыл бұрын
@@joshtriedcoding the man himself. Just what I wanted to hear. We’re all turned in
@mohaniya15
@mohaniya15 Жыл бұрын
Which snippet extension do you use? I like the way you can just write state and the useState is autocompleted.
@aerotheory
@aerotheory Жыл бұрын
He has a video: How to create Custom Snippets in VSCode (with examples)
@Sasuke-px5km
@Sasuke-px5km 5 ай бұрын
Hello is there any handling refresh token using axios related to this video?
@justiceessiel6123
@justiceessiel6123 Жыл бұрын
What is the "on the edge "exactly..
@nuuklu3189
@nuuklu3189 Жыл бұрын
well explained. is there a github link ?
@bongjames2222
@bongjames2222 Жыл бұрын
nextjs 인증강의를 검색하던중 찾았습니다. 감사합니다. nextjs 를 처음배우는데 영어를 몰라서 자동번역으로 보면서 겨우겨우 따라하고 있습니다.
@devotee9606
@devotee9606 7 ай бұрын
Thanks
@saharilarshad1628
@saharilarshad1628 Жыл бұрын
Useful knowledge.. Hope, next will be NextAuth with the JWT access token Register, Login and User Access Role..!
@ghalitsar2730
@ghalitsar2730 Жыл бұрын
awesome video ! , can u implement refreshToken on the next video ... cant wait for another video from u
@alowais900
@alowais900 8 ай бұрын
Yes please! Agreed, a refreshToken would be awesome.
@ambrosebeavers
@ambrosebeavers Жыл бұрын
Hey Josh I notice that when I redirect the upload still shows the path of the previous page. Any way to fix that
@vernevens1598
@vernevens1598 4 ай бұрын
Who is vercel and why would i give a hoot about their best practices?
@easy-peasy-tutorials
@easy-peasy-tutorials Жыл бұрын
if we have to show user data in /dashboard page , how can we do that we can do so by getServerSideProps but what if we have to show userData in Navbar(email) , /profile page for client-side we can use useEffect BUT what if we have to show data in Navbar, dashboar,profile page on the very first page load
@christianstamati
@christianstamati 8 ай бұрын
how to can i implement logout? I just need to delete the cookie on client side?
@timur.shhhhh
@timur.shhhhh 3 ай бұрын
what does Edge mean, I often hear it, but I can’t understand it, because English is not my main language, is it like a browser from Microsoft?
@rizkifahruroji5047
@rizkifahruroji5047 Жыл бұрын
Thank You. this is very petrified doing authentication in middleware. but something strange happened to my nextjs app in production mode. I logged out and changed the maxAge in the serial cookie to -1. cookies deleted successfully but i can still access admin page. sometimes the data displayed is data from other users at different levels who have logged in on their respective devices. Please help and sorry for my english
@muhammadbilal6865
@muhammadbilal6865 4 ай бұрын
his method isnt the best
@alexiglesias5166
@alexiglesias5166 4 ай бұрын
I'm having the same problems
@nasirify
@nasirify 9 ай бұрын
OH GOSH!!! Thanks JOSH :)
@webber5629
@webber5629 Жыл бұрын
If user is logged in and if they still wanna access /login then how to redirect them to " /" page
@dawitminale2775
@dawitminale2775 9 ай бұрын
is it the same for next 13 ?
@kirielbe
@kirielbe Жыл бұрын
Hi, where can I find this example on your github?
@chamir4614
@chamir4614 Жыл бұрын
Where did you get that wallpaper? It's really really cool!
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Cheers dude, the service providing that was called Wallpaper Engine on Steam
@nguyennam5056
@nguyennam5056 Жыл бұрын
Why can not i see you set cookie?
@LeagueofLegendMoment
@LeagueofLegendMoment Жыл бұрын
hi Josh, your video helpful with me, when i do with my project, it run perfectly in local, but when i deployed on vercel, the middleware not working, it mean the JWT - verifyToken not working, token isn't authenticated. Can you help me.
@kamalheydari8612
@kamalheydari8612 Жыл бұрын
hey, I'm having the same issue. Have you found any solutions for it?
@ashankarunaratne3424
@ashankarunaratne3424 Жыл бұрын
Hey Josh thanks for this, I'm using this for my new project but I'm having an issue how do I protect dynamic routes? for example I want to protect this route "/customer/[id]"
@joshtriedcoding
@joshtriedcoding Жыл бұрын
It's easiest to validate the JWT through a middleware and allow a next() only if the token is valid
@ashankarunaratne3424
@ashankarunaratne3424 Жыл бұрын
@@joshtriedcoding Thanks Josh 🍻
@jotaroisdarius1918
@jotaroisdarius1918 Жыл бұрын
Thank you so much!
@agimalma5321
@agimalma5321 Жыл бұрын
bro i haved try this, and i have problem because this not use the next auth to get the session user, my asking is "how to get session user in dashboard ? or how we can show user who login to the app"
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Within next-auth, you can use the getServerSession or client side useSession for that
@Mark-lg2qe
@Mark-lg2qe 8 ай бұрын
Do you have a github link?
@bongjames2222
@bongjames2222 Жыл бұрын
혹시 trpc 를 사용하지 않고 middleware 를 만든 영상도 있습니까?
@LazyShady
@LazyShady Жыл бұрын
Dang..Im using normal NextJs and im stuck on the OnSuccess part.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
You could return this from the middleware like {success: true, data: ...} and then check for the success property in your trycatch! :D
@LazyShady
@LazyShady Жыл бұрын
@@joshtriedcoding dude thats such a better idea. Right now im using axios to post formdata to nextApi and waiting for a response 200 to router.push 🫢
@joshtriedcoding
@joshtriedcoding Жыл бұрын
@@LazyShady cheers man
@ambrosebeavers
@ambrosebeavers Жыл бұрын
Wonderful!
@oopss794
@oopss794 Жыл бұрын
6:57 is using next-auth more secure?
@joshtriedcoding
@joshtriedcoding Жыл бұрын
next-auth gets a lot of things about web-app security right out of the box and encourages security best practices, such as avoiding using password auth
@raymondmichael4987
@raymondmichael4987 Жыл бұрын
Is it possible to automatically logout the user immediately when the cookie expire? 😊,
@developer_hadi
@developer_hadi Жыл бұрын
No but when he try to send a request you can check if his token is expired and if it is, you can logout the user
@raymondmichael4987
@raymondmichael4987 Жыл бұрын
@@developer_hadi thanks buddy
@kevinpuchaicela6737
@kevinpuchaicela6737 Жыл бұрын
thansk!
@webber5629
@webber5629 Жыл бұрын
Code please ?
@aerotheory
@aerotheory Жыл бұрын
trpc route structure changed.
@joshtriedcoding
@joshtriedcoding Жыл бұрын
Yeah I was a bit confused at first, they did it again
@andrebozzato
@andrebozzato Жыл бұрын
top!
@marcinburzynski8082
@marcinburzynski8082 11 ай бұрын
just so you know. `!!"" === false`
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 10 МЛН
Harley Quinn lost the Joker forever!!!#Harley Quinn #joker
00:19
Harley Quinn with the Joker
Рет қаралды 27 МЛН
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 51 МЛН
Fetching Data Doesn't Get Better Than This
6:58
Josh tried coding
Рет қаралды 108 М.
Lucia Auth in 9 minutes
8:50
monstajoe
Рет қаралды 9 М.
NextJS Authentication with Server Actions - Learn to build from scratch!
33:15
The Ultimate Guide to Next Auth - Everything You Need
1:36:26
Brett Westwood - Software Engineer
Рет қаралды 57 М.
My Favorite Tech Stack for 2024
10:05
Josh tried coding
Рет қаралды 25 М.
We Need to Talk About Redis.
14:55
Josh tried coding
Рет қаралды 89 М.
This UI Library Keeps Crushing It
4:36
Josh tried coding
Рет қаралды 68 М.
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 10 МЛН