Some of you have this concern, when you use ['/admin'] for matcher config. only the /admin is going to be private not all admin routes like /admin/posts. You can use ["/admin/:path*"] to restrict all of the admin path.
@richardkirigaya8254 Жыл бұрын
what is :path* ? lets say i want to restrict a "create" route in the admin page, so it becomes ["/admin/:create*] ? And if i have 5 pages in the admin page i have to repeat this 5 more times ??
@rogerhoffmann Жыл бұрын
@@richardkirigaya8254 path is anything after admin, you don't need to replicate for each route
@markkkkk07 Жыл бұрын
AMAZING!! Simple, fast and understandable explanation
@wazzadev72092 жыл бұрын
Your next auth tutorials have been helpful and very straight forward, thanks.
@vladsvyrydonov1793 Жыл бұрын
Very nice, just everything I was looking for.
@cdromance2705 Жыл бұрын
How do you get your VSCode to show the param definitions on hover for the jwt callback at 6:22? Having something like this in my ide would make my life much easier.
@zizzz10 Жыл бұрын
Can you declare matchers so that it matches all routes except /login?
@faruksardar88292 жыл бұрын
Simple, Easy to Understand, Thank for so much Niraj for this video
@Iacapuca2 жыл бұрын
This approach only works for JWT tokens at the moment, next-auth middleware dos not support session based auth.
@BuntyWP Жыл бұрын
Very clean and simple explanation. Thank You
@ingolesubodh2 жыл бұрын
goddamn bro you are awesome !! you will go big soon
@thebocksters27564 ай бұрын
how you know that if authorized function returns true then the middleware gets triggered, I tested it with "return true" in the callback and it didn't fired the middleware
@himanshu39846 ай бұрын
when deployed on vercel middleware is broken it just redirect to signin even i try login and successfully loggedin it do not consider protected routes of nextauth and always redirect to signin when i access them
@mertdr2 жыл бұрын
Thanks for the video. One question though, how could you use withAuth for multiple cases on middleware routes? After NextJS removed support for multiple middleware files, withAuth looks like pretty useless. Creating a standard NextJS middleware function and catching session and then applying rules is a better idea, am I right?
@vatsalcodes Жыл бұрын
how to change the redirect url when we try to access secured page without being authenticated
@deathdefier45 Жыл бұрын
Hey Niraj, is it possible to user a matcher that works on dynamic pages that use a slug? Please help me with a solution if you know how to, Thanks!
@giorgosterzis3331 Жыл бұрын
I have added this to export const config = { matcher: ["/shop/portal/:path*"] }. But, when I try to access/shop/portal I get "TypeError: Class extends value undefined is not a constructor or null". Can anybody help?
@ivanmakevic8258 Жыл бұрын
how do you authenticate users if they want to login with gmail or github for example?
@k2nnethtan949 Жыл бұрын
Possible to further the next episode with Prisma mongo?
@rh9037 Жыл бұрын
I'm running into the issues where role doesn't seem to exist in the (params.user?.role) callback function of [...nextauth].ts. I added it in the list of returns for a user but it still doesn't seem to exist. Has anyone else run into this issue?
@amadacruse41932 жыл бұрын
Thx for awesome tutorial sir. My problem is that i added exactly these two lines on my middleware.js on root folder export { default } from "next-auth/middleware" export const config = { matcher: ["/", "/admin/privilages/dashboard"] } and i can still visit these pages..... its like middleware doesnt woek at all. any idea why. ty in advance!
@Peter-yd2ok2 жыл бұрын
did you solve this?
@madhawapriyashantha37222 жыл бұрын
i had the same issue .i fixed it by renaming middleware.ts to _middleware.ts
@Peter-yd2ok2 жыл бұрын
@@madhawapriyashantha3722 but isn't that old way of creating a middleware?
@madhawapriyashantha37222 жыл бұрын
@@Peter-yd2ok yep but i had installed next 12.0
@Peter-yd2ok2 жыл бұрын
@@madhawapriyashantha3722 ohh. I had tried this old middleware syntax but then i got errors while deploying.
@blu5037 Жыл бұрын
Awesome video, man! many thanks :)
@evgeniy33702 жыл бұрын
Hi. if the "pages" folder is nested in the "src" folder, which is located along with the middleware file in the root of the project, will the middleware work?
@isaacpriestley2 жыл бұрын
I'm using Rails devise-jwt as my backend, and I'm trying to figure out how to take the JWT created by my backend and use it in my Next client...
@prasadbeligala Жыл бұрын
Thanks for the simplified explanation. At 6:46 can we add more user roles and redirect to different routes?
@fsniraj Жыл бұрын
I think so the only way to find out is just try.
@prasadbeligala Жыл бұрын
@@fsniraj At the end found a way to do it.. :) Looks like middleware is the best way to restrict access on the server. Thanks again for this valuable video Niraj
@SSango-hk9sm Жыл бұрын
Hie Niraj great tut once again. I have a question. I have two tables a users and workspaces table linked by a one to many relationship. I would like to implement an onboarding experience whereby after the user is signed in I would like to check if that user has a workspace linked to his/her user account if not then redirect to the page where you can create the workspace. I'm failing to figure out how I can implement that in the middleware. I'm using postgre and prisma adapter by the way.
@mpowereer69922 жыл бұрын
But i can still go to /signup page or /signin page, how to prevent from visiting this routes when being authenticated?
@beverlyHillsAgent2 жыл бұрын
in this example, no matter which page you go to, if you are an admin, the url will be rewritten to admin page. In other words, no matter which page you go to, it will always show the admin page?
@wazzadev72092 жыл бұрын
I have a question, what if you want to make some routes admin protected and others basic user protected routes?
@fsniraj2 жыл бұрын
You can check the incoming request url and try to log the req object. And according to the request you can change rewrite or redirect response.
@wazzadev72092 жыл бұрын
@@fsniraj thanks again
@kakun72382 жыл бұрын
the jwt callback is not working for me the roles is there when i console log the params object but not in the response after signing in
@fsniraj2 жыл бұрын
Session and the jwt callback only works on the first login so make sure you removed the cookie from application tab and then try.
@kakun72382 жыл бұрын
@@fsniraj I did that too but if I bind it to email or any other pre fixed token attribute I get the response through jwt callback Sorry to bother you but another question too can't we redirect the user after login when using a custom login?
@fsniraj2 жыл бұрын
If you need any custom behavior when you have to do some experiments with your code. And to redirect after login you can use useSession hook and the next/router.
@tomyyoung26246 ай бұрын
Yes a fix, Especially for a client website
@Prathamesh-o6n Жыл бұрын
do one video of how to connect with an api and fetch users in login
@MohamedAbouelnasr-z3s Жыл бұрын
2 days looking for solution thank you
@shfsakib3392 жыл бұрын
Hi. Is there any way to prevent user not to go admin pages and also prevent admin for go to user pages. I don't wanna make folder for each user and check startwith [ if(url.startwith('/admin')) ] the example given in google. Please help if you can. I'm new to nextjs.
@masonpool5257 Жыл бұрын
He explains it in the video, if you set up the 'export const config = { matcher: []}', you can specify which routes require an auth token. example: export const config = { matcher: ["/admin", "/dashboard/:page*"](for all pages along the dashboard route)}
@shahriardhruvo62812 жыл бұрын
Wow, great video
@haian_2 жыл бұрын
Hi, please implement with next js 13
@iqbalherlambang58656 ай бұрын
thanks
@ashimov1970 Жыл бұрын
why among indians pronouncing "sh" correctly is a huge issue?