#Middleware issue

30 messages · Page 1 of 1 (latest)

prime willow
#

anyone ?

chrome arrow
#

does this happen on production or development mode?

prime willow
#

both

chrome arrow
#

does your conditional statement work?

#

If you add a console.log will it execute it?

prime willow
#

yup

chrome arrow
# prime willow yup

I have almost the same issue, but for me it works fine in development but not in production

chrome arrow
# prime willow yup

try installing the canary version of next.js where have a lot of bugs fixed npm install next@canary

prime willow
#

wait I found that home route is not matching

#

I have the lang in pathname for exemple /en | /fr | /de

chrome arrow
#

Ye I see with next-translate

prime willow
#

should I add each to protectedPaths array ?

chrome arrow
#

translation prefixes are not be part of pathname I think

chrome arrow
prime willow
chrome arrow
#

ok..

chrome arrow
prime willow
#

I agree

#

do you have another solution ?

chrome arrow
#

No sorry idk

#

Can you help me with my code?

export async function middleware(request) {
    const cookie = request.cookies.get("token")?.value;

    if (request.nextUrl.pathname === "/" && cookie) {
        return NextResponse.redirect(new URL("/home", request.url));
    }
}
#

Im not using next-auth, should I use it

prime willow
#

Create a ticket I'll answer you there 😄

chrome arrow
#

I don't know if these are good manners, help then ask for help xd

#

Why do you use url.searchParams.set("callbackUrl", pathname); ?

prime willow
#

to keep the callback in the url

chrome arrow
#

ok