Next.js 13 Role Based Authorization with Middleware & NextAuth

preview_player
Показать описание


My courses:

💻 MY GEAR

Connect with me:

Timestamps
00:00 What this video is about
00:09 Setup the example project
05:53 Adding example pages to the app
08:00 Add Middleware to protect whole app
12:29 Adding Role based authorization

This video was sponsored by Brilliant.
Рекомендации по теме
Комментарии
Автор

Thanks a lot Tuomo for this video. It's a lot clearer to me now how to implement role based authorization in Next.js. My only question is how to do this with email password authentication instead of Github authentication. Greetings, Anthony

AnthonyCandaele
Автор

this video really help a lot for me to understand the most basic structure of Role-based access control (RBAC) of next js.
Thank you so much!!

timmywong
Автор

Thanks for this bro, Usually the username, email, image only will store in database for the backend? and the exp date is not usually included in the frontend part when sending the data to the backend?

blackbeans
Автор

Hello! Could you please advise me how to set up role issuance in a production application? After all, in the video there was a rigid binding by hand.
Maybe it should be connected to a database or something like that? Could you please answer this question or make a detailed video on this topic?
Thanks!!!

parmetra
Автор

Sorry sir I wil watching your video very late because I am few days sick. Love from India ❤

wassu
Автор

thanks your english is very good can all finnish speak this well english

gojamoja
Автор

i am new to backend web development, i got the machinisim of how this work logically but was a bit confused. If i m correct right now the role assignment is hardcoded right? in real world, how would we handle and assign role to a user? it sounded like its going to be very complicated and required to set up admin pannel and check role from user database?

Adrian-mugg
Автор

Sir, suppose i have 2 role in my project admin and superadmin. Now how to protect admin from superadmin and superadmin to admin

sayedarifin
Автор

Hi
How to add in next-intl .. because in middleware i am getting the issue.. please help me if possible

saadah
Автор

Thanks for clarifying the api routing for next auth! I was wondering why nextauth wasn't working with my other new api routes in the app folder.

This and your earlier nextauth for nextjs13 tutorials are the most in depth tutorials on the new app router features i've seen so far

Squink
Автор

Tuomo, I have my middleware file in the root of my project exactly as you have laid out in this tutorial, using next 13.2.4 and next auth ^4.22.0. If i attempt to access a page that is blocked by the middleware, I login but the callback is stuck in a loop on the same login screen. is this an issue the the version of next/next-auth?

AntNZ
Автор

how can I check role base for dynamic route
if(req.nextUrl.pathname === "/artist/[id]") {
//do something
}
can I use that above code

painghtetaung
Автор

Is this middleware strategy compatible with client components or only with server components?
Can both kinds of components coexis using this middleware strategy?

forcohen
Автор

thank you so much, I didn't know that middleware should be as the same level as app folder, I was putting it in the root and it wasn't working

Kimitri
Автор

The [...nextauth] file works in the app directory now.

shawn-skull
Автор

There is a little problem with that approach, if of any importance to anybody. withAuth doesn't work on the Edge Network (which totally different from the browser by the way), and guess what if you don't run serverless this will be your second main option. but thanks any way

omarshehab
Автор

Love your tutes. Helped me out a few times now. Having a small issue with this one tho. Got it mostly working, but for some reason the admin pages are only blocked if I go directly to the url using the address bar... following a Link however allows me access to the protected pages. Any ideas? Im just using the standard nextjs Link components, but they appear to be ignoring the middleware.

havanapple
Автор

Hello Tuomo,
Thank you for the sharing the valuable information. Can you please share the code as well ?

AmitSoni-ez
Автор

tanks for the video, can we have the source code ?

brobruberty
Автор

It's a shame that simply having nextjs middleware is adding 100 ms overhead delay to every request of your

Vantivify