Effortless Protected Routes In Next.js Using Middleware
Вставка
- Опубліковано 5 вер 2024
- 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.
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!
Happy it helped!
No bs with an example and straight to the point. Thank you!
You’re welcome!
Thank you so much. Very clean and this is what I needed!
Happy to hear it!
Thanks for doing this video Ryan. I was stuck on this for 2 days lol
Happy it helped!
So straight forward and easy to understand. Thank you
You’re welcome
This is a really helpful compliment their docs. Thank you!!
You’re welcome!
Thank you for such a simple tutorial
You’re welcome
This was just what I needed. Thank you very much. Simple and easy to understand.
Hey, i like this, so easy to make, thanks bro, greetings from Argentina.
You’re welcome!
how do i make it dynamic? without changing user manually in middleware
export const config = {
matcher: ['/((?!api|_next/static|_next/image|.*\\.png$).*)']
};
With this you can run your middleware on every request
@@benjaoliva3383 he's asking how do you know whether the user is logged in or not
Really helpful better than the HOC approach
Super helpful! Thanks for creating this
Crazy, so that fixed my JWT authentication protected route problem
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
Thanks. Good feature
If you have a src folder, try placing it in there. My middleware didn't run until I did that.
D@mn true, I appreciate ya
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
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…
but while creating a build the middleware.ts file doesn't work then what will be the solution for that edge case ?
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 ?
Middleware making the routing slower, any solution?