Next.js Discord

Discord Forum

next-auth middleware not redirecting to the sign in page

Answered
Forest yellowjacket posted this in #help-forum
Open in Discord
Forest yellowjacketOP
Hi, I'm trying to secure some of my pages using next-auth. But my middleware does not redirect to sign in page. My middleware:
export { default } from "next-auth/middleware"

export const config = { matcher: ["/brewstation"] }

in next-auth options I have custom signIn page like this:
   pages: {
        signIn: '/login',
        //signOut: '/logout',
        error: '/login'
    }

If I try to get to the /brewstation without logged user - session is empty - nothing happens. Any redirect to singIn page. I can freely visit /brewstation route. Any ideas?
Answered by Forest yellowjacket
Solved. version 13.4.7 works. I forgot --build in docker......
View full answer

4 Replies

Forest yellowjacketOP
Update: I had middleware.ts in wrong folder. Anyway, still facing this issue: Module parse failed: Identifier 'NextResponse' has already been declared (3:6)
I tried to downgrade Next to version 13.4.3 or upgrade on 13.4.7 - https://github.com/auth0/nextjs-auth0/issues/1239 - but that won't help.
Forest yellowjacketOP
Solved. version 13.4.7 works. I forgot --build in docker......
Answer
@Forest yellowjacket Solved. version 13.4.7 works. I forgot --build in docker......
Nice to see that you solved it, forgetting flags and basic things happens to all of us 😭