Next.js Discord

Discord Forum

Some of conditions are omitted by Middleware

Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
Original message was deleted.

49 Replies

Peterbald
I think it is because of token of cookies. Did you check your NextRequest cookie if there is token?
Check that token first
Okay
Peterbald
Can you check if token is null or not?
So you mean token is not null, if so great. You can advance step 1
req.nextUrl.pathname.startsWith('/home')
This condition is working properly?
I think not
You can use RegExp instead of that
const SUBSCRIPTION_NEEDED_ROUTES = ["/agreements/(.*)", "/legal-manager(.*)", "/chatlegal(.*)"]; function matchesSubscriptionRoute(str: string) { return SUBSCRIPTION_NEEDED_ROUTES.some(pattern => { const regex = new RegExp(pattern); return regex.test(str); }); }
Do you understand what I mean?
That is one example if NEXT URL is match to some URL's array
You can customize this example to adjust your project
middleware.ts
Peterbald
Oh this is my project
Not a link
Peterbald
Okay can you share with me exact errors, when you click which route?
Peterbald
I think you condition boundary is not working properly.
So please use my boundary condition
Using RegExp
great
Okay
Peterbald
You said checking COOKIE is fine
?
Original message was deleted
Peterbald
If so what you mean?
BTW where are you from?
You can ignore about clerk
Just consider about route boundary condition
great
Peterbald
Okay let me try with your middleware file
Peterbald
Please try like this
Sorry try like this
Peterbald
Yeah it could be
If it works, then okay
Which page exactly?
when there is token? or not?
Please erase the space between else and if
like else if
Peterbald
Where does your all boundary conditions?
if(!token)?
Yeah except for this
I mean you have to replace all boundary conditions as a matchURL(req.nextUrl.pathname,"/home(.*)") type instead of req.nextUrl.pathname.startsWith('/adlog')
got it?
even if(token)
What i mean is that I think req.nextUrl.pathname.startsWith('/adlog') boundary condition is not working properly
okay?
Please DM me