How to Protect Routes in Next.js using Middleware
Вставка
- Опубліковано 4 жов 2024
- In this video, we will see how to dockerize a next js application in two different scenarios.
Link to next js middleware matcher config:
nextjs.org/doc...
How to dockerize a next js application
• How to dockerize a nex...
Comment down what else you would like to see, I am always open to suggestions.
You guys can send UIs which you want me to code, suggestions may not be restricted to any specific tech. Let me know the tech stack in which you want it, if I can pull it off, I will surely post it for you guys.
Like, share, and subscribe if you want to see more of such videos.
follow me on Instagram:
/ devsedated
follow me on Twitter:
/ devsedated
Let's build a strong community and peer learn coding, a great career, and an income source.
Song: BIMINI - No Way (with Avi Snow) [NCS Release]
Music provided by NoCopyrightSounds
Free Download/Stream: ncs.io/noway
Watch: AT/youtube
The font is too large, your code is still readable...
same thing could've been done with BrowserRouter?
PS: I am totally new with react so this thing you've done is just new for me
Hey thanks for the question,
1. BrowserRouter is not used in next js framework for routing, next js has it's own way of handling routing using pages or app router.
2. BrowserRouter handles the logic in client side and can sometimes momentarily expose protected routes as it waits for the app to render ( in my experience, not sure if it can be mitigated ).
3. Middleware handles the protection completely on server side and executes much before in the lifecycle of a request, making it much more secure as it doesn't have to wait for the app to render.
Hope, this helps.
I have a question. If u can't access cookie storage in middleware, how are you gonna check for the JWT or any token?
Hey, sorry If I was not clear in the video, but what I said was you cannot access session or local storage, but you can access cookies.
@@TheSedatedDevoh, thank you for clarifying that!