Next.js Discord

Discord Forum

Trying to setup NextAuth with middleware.tsx file - login is happening but always returns to login

Answered
Forest bachac posted this in #help-forum
Open in Discord
Forest bachacOP
Trying to setup NextAuth with middleware.tsx file - login is happening and session is created in database but page never returns to page that is behind matcher.

Middleware.tsx File is:

import { withAuth } from "next-auth/middleware"; export default withAuth({ secret: process.env.SECRET, }); export const config = { matcher: ["/dashboard"] }

I've also tried:

export { default } from "next-auth/middleware" export const config = { matcher: ["/dashboard"] }

Without middleware file App Directory redirection is working fine
Answered by Forest bachac
Figured it out
View full answer

3 Replies

Forest bachacOP
update: I don't know if this has as much to do with middleware as nextauth configuration
you might want to use debugger to break inside middleware to see if requests are processed in middleware and a session cookie is passed in Http request header.
Forest bachacOP
Figured it out
Answer