# Next.js Issue Tracker Middleware

**URL:** <https://forum.codewithmosh.com/t/next-js-issue-tracker-middleware/23301>\
**Category:** Next.js\
**Created:** [October 27, 2023, 5:51pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-middleware/23301 "2023-10-27T17:51:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [October 27, 2023, 5:51pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-middleware/23301/1 "2023-10-27T17:51:46Z")

</div>

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:

```auto
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.
```

---

<div class="post-metadata">

**Author:** ![petervel](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/petervel/32/5094_2.png) [@petervel](https://forum.codewithmosh.com/u/petervel)\
**Post date:** [November 21, 2023, 1:19pm UTC](https://forum.codewithmosh.com/t/next-js-issue-tracker-middleware/23301/2 "2023-11-21T13:19:27Z")

</div>

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 😉  
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.
