Next.js Issue Tracker Middleware

The middleware component of the issue tracker seems to work fine except in one spot. I’m not sure if it broke when I added the “Assign User” components or it was broken from before.

In my middleware component, I have the following:

export {default} from 'next-auth/middleware'

export const config = {
    matcher: [
        '/issues/new',
        '/issues/edit/:id+',
    ]
}
``

When I am not logged in, all works perfectly.  But when I am logged in, the /issues/new page keeps pushing me back to the login page, even though I am already logged in.  No matter what it always goes back to login.  Refresh/restart - nothing seems to fix it.

I tried it with a trailing slash:  /issues/new/ and without /issues/new.  It just never realizes I am logged in.  But only on that page.

If I remove that line from the middleware, the form works fine.  It's all related to the next-auth and middleware component.

The /issues/edit/ page works as it should.  If logged in, it works.  If logged out, it goes to sign-in.
1 Like

Having the same kind of issues. My middleware isn’t working correctly either, no idea why. Whenever I hit one of the matching urls it shows me a login screen. When I click the login button it redirects me to the same login screen. Infinite loop.
When I rename the middleware.ts file (disabling it), everything works fine. Except then I’ve disabled my security check :wink:
Anyone know what might be causing this, and better yet, how to fix it?

EDIT: I think I may have fixed this by adding

session: { strategy: "jwt", },

to the authOptions.ts file. It didn’t seem to be needed before, but for some reason at this point signin was suddenly broken, and adding that (like Mosh had) fixes the issue.