Effortless Protected Routes In Next.js Using Middleware

  Рет қаралды 28,543

Code Ryan

Code Ryan

Күн бұрын

Github project: github.com/cod...
In this engaging tutorial, we dive into the world of Next.js to explore the powerful role of middleware in creating secure, protected routes. Tailored for both beginners and seasoned developers, the video offers a concise yet comprehensive guide, demonstrating step-by-step how to implement middleware for route protection in Next.js applications.

Пікірлер: 51
@Keeptheflameband
@Keeptheflameband 27 күн бұрын
I have been loosing sleep trying to run some middleware with token auth and this is just what I needed thank you very much! From: a self learning developer.
@coderyan
@coderyan 27 күн бұрын
Happy it helped!
@cesarpizarra1773
@cesarpizarra1773 5 ай бұрын
Man, thank you for this tutorial! I was stuck for hours trying to figure out why my middleware wasn't working. I had placed the middleware file in the app folder and tried debugging it, but nothing worked. Then, I found your video and learned to place the middleware outside the app folder-and it worked!
@coderyan
@coderyan 5 ай бұрын
Happy it helped!
@marie-elizeventer7080
@marie-elizeventer7080 10 ай бұрын
This was just what I needed. Thank you very much. Simple and easy to understand.
@zb2747
@zb2747 6 ай бұрын
No bs with an example and straight to the point. Thank you!
@coderyan
@coderyan 6 ай бұрын
You’re welcome!
@sandrotabatadze3768
@sandrotabatadze3768 4 ай бұрын
short and understable! without any unnecessary things! thanks man!!
@coderyan
@coderyan 4 ай бұрын
You’re welcome!
@yushankkashyap7771
@yushankkashyap7771 2 ай бұрын
Man you are a saver. I have wasted so much time on this and you explained it so well. I was stuck due to middleware being in the app folder. Thank you!😄
@samnmeje3486
@samnmeje3486 11 ай бұрын
So straight forward and easy to understand. Thank you
@coderyan
@coderyan 11 ай бұрын
You’re welcome
@csdevelops7
@csdevelops7 6 ай бұрын
Thanks for doing this video Ryan. I was stuck on this for 2 days lol
@coderyan
@coderyan 6 ай бұрын
Happy it helped!
@MuhamadAzizPrasetyo
@MuhamadAzizPrasetyo 6 ай бұрын
Thank you so much. Very clean and this is what I needed!
@coderyan
@coderyan 6 ай бұрын
Happy to hear it!
@AHMED-dl5hn
@AHMED-dl5hn 2 ай бұрын
thanks a lot man, simple and efficient
@coderyan
@coderyan 2 ай бұрын
Happy it helped!
@joze.rios44
@joze.rios44 10 ай бұрын
Hey, i like this, so easy to make, thanks bro, greetings from Argentina.
@coderyan
@coderyan 10 ай бұрын
You’re welcome!
@abdilaahimowliud7556
@abdilaahimowliud7556 Ай бұрын
Thank you so much. Very clean
@coderyan
@coderyan Ай бұрын
Happy it helped!
@tigana
@tigana 7 ай бұрын
This is a really helpful compliment their docs. Thank you!!
@coderyan
@coderyan 7 ай бұрын
You’re welcome!
@Alim-yo3sc
@Alim-yo3sc 6 ай бұрын
Thank you for such a simple tutorial
@coderyan
@coderyan 6 ай бұрын
You’re welcome
@fabio9311
@fabio9311 9 ай бұрын
Super helpful! Thanks for creating this
@mrjessan2343
@mrjessan2343 8 ай бұрын
Crazy, so that fixed my JWT authentication protected route problem
@israelzorzor5805
@israelzorzor5805 7 ай бұрын
Really helpful better than the HOC approach
@pritishmendhekar360
@pritishmendhekar360 2 ай бұрын
Thanks very helpful😶‍🌫
@fillipeamg5877
@fillipeamg5877 6 ай бұрын
Thanks. Good feature
@rahulram4300
@rahulram4300 26 күн бұрын
This was very helpful indeed to understand how we can protect the routes. But I have a doubt here, if the user is already authenticated, he should be navigated to the mainPage instead of signIn page. We can write a condition for that here and add signIn page to the matcher but wouldn't it make the middle ware run infinitely because it will rerun the mainPage because user exists?
@hankersoree
@hankersoree 11 ай бұрын
how do i make it dynamic? without changing user manually in middleware
@benjaoliva3383
@benjaoliva3383 10 ай бұрын
export const config = { matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)'] }; With this you can run your middleware on every request
@thatsalot3577
@thatsalot3577 10 ай бұрын
@@benjaoliva3383 he's asking how do you know whether the user is logged in or not
@tigana
@tigana 7 ай бұрын
If you have a src folder, try placing it in there. My middleware didn't run until I did that.
@morgan24TH
@morgan24TH 7 ай бұрын
D@mn true, I appreciate ya
@habitathomies6049
@habitathomies6049 3 ай бұрын
Legend! I was stuck on this for ages, thanks!
@danielcaro1020
@danielcaro1020 Ай бұрын
ohh thanks!
@MrSeredan
@MrSeredan Ай бұрын
If I have a middleware with localization and a middleware with route protection, how do I make different configurations for the application?
@minhaz3193
@minhaz3193 6 ай бұрын
what if i want to have multiple middleware functions? where would they go since we have only one middlware.js file and one export for config
@benjamingoller6267
@benjamingoller6267 10 ай бұрын
I am frustrated at the moment. I am using server actions eg for database queries. However, whatever I do, I cannot protect the server function from being accessed from anyone from the client side. The function is in a folder utils alongside app. The can use it from client side but so can anyone! I have looked everywhere, but I cannot seem to find how to handle that…
@DickyFirmansyah-u9o
@DickyFirmansyah-u9o 7 ай бұрын
so i have setup my middleware and redirect to login page if its not logged in and after login i setup an encodedOriginUrl to go back to that requested page, but can i check if theres a page exist or not in my apps inside middleware? so the user should not go to login page and after login they found that the page is not found, so i just want the user just directly redirect to not found page and not login page if the page doesnt exist in my apps
@VishalMewada-jq4qk
@VishalMewada-jq4qk 9 ай бұрын
but while creating a build the middleware.ts file doesn't work then what will be the solution for that edge case ?
@EseosaOsayi
@EseosaOsayi 5 ай бұрын
Winter is coming, 😂 i spy a game of thrones fan
@devrano48
@devrano48 10 ай бұрын
Middleware making the routing slower, any solution?
@ThanHtutZaw3
@ThanHtutZaw3 Жыл бұрын
My Cookies are exist in normal api call but when I call 2nd api call in service worker notification FCM , I don't get firebase cookies in Next.js api . Is it cross origin issue ?
@adnanrruka5152
@adnanrruka5152 4 ай бұрын
thnx
@coderyan
@coderyan 4 ай бұрын
You’re welcome
@rithikguleria8278
@rithikguleria8278 3 ай бұрын
Wonderful🤍
@coderyan
@coderyan 3 ай бұрын
Thank you!
Step-by-Step: Implementing Social Auth in Next.js
22:53
Code Ryan
Рет қаралды 2,2 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
NextJs Middleware | How it Works & Real Use Cases
17:26
Hamed Bahram
Рет қаралды 27 М.
Protected routes in Nextjs 15 | Protect Routes with Middleware Nextjs
27:33
JavaScript Unleashed
Рет қаралды 4,1 М.
NextJS Parallel Routes Explained with a Simple Example
14:04
Dave Gray
Рет қаралды 18 М.
Learn Express JS In 35 Minutes
36:03
Web Dev Simplified
Рет қаралды 891 М.
Learn Next.js Intercepting Routes In 11 Minutes
11:08
Web Dev Simplified
Рет қаралды 40 М.
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 243 М.
Next.js App Router: Routing, Data Fetching, Caching
14:32
Vercel
Рет қаралды 346 М.
Protect Your API - Next Auth Middleware
8:05
Full Stack Niraj
Рет қаралды 35 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.