# NextJS 15 + @auth0/next-js 4.4.2 Login issues

**URL:** <https://community.auth0.com/t/nextjs-15-auth0-next-js-4-4-2-login-issues/185785>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [April 22, 2025, 8:13am UTC](https://community.auth0.com/t/nextjs-15-auth0-next-js-4-4-2-login-issues/185785 "2025-04-22T08:13:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnolan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tnolan/32/53136_2.png) [@tnolan](https://community.auth0.com/u/tnolan)\
**Post date:** [April 22, 2025, 8:13am UTC](https://community.auth0.com/t/nextjs-15-auth0-next-js-4-4-2-login-issues/185785/1 "2025-04-22T08:13:50Z")

</div>

Hi there,

I updated to the latest version of NextJS & `auth0/next-js` recently and have been having problems with getting things to work since the upgrade. After creating my `middleware.js` as advised [here](https://github.com/auth0/nextjs-auth0/tree/main?tab=readme-ov-file#4-add-the-authentication-middleware), it looks like:

```javascript
import { auth0 } from '@/lib/auth0';
import { NextResponse } from 'next/server';

export async function middleware(request) {
    const authRes = await auth0.middleware(request);

    if (request.nextUrl.pathname === '/api/healthcheck') {
        return NextResponse.next();
    }

    if (request.nextUrl.pathname.startsWith('/auth')) {
        return authRes;
    }

    const session = await auth0.getSession(request);

    if (!session) {
        console.log('User not authenticated, redirecting to login page');
        // user is not authenticated, redirect to login page
        return NextResponse.redirect(new URL('/auth/login', request.nextUrl.origin));
    }

    return authRes;
}

export const config = {
    matcher: [
        /*
         * Match all request paths except for the ones starting with:
         * - _next/static (static files)
         * - _next/image (image optimization files)
         * - favicon.ico, sitemap.xml, robots.txt (metadata files)
         */
        // '/((?!_next/static|_next/image|site.webmanifest|favicon.ico|sitemap.xml|robots.txt|api/healthcheck).*)',
        '/((?!api|_next|site.webmanifest|favicon.ico|sitemap.xml|robots.txt|.*\\..*).*)',
    ],
};

```

Once I log in, I can see my profile coming back correctly and it looks like I’ve authenticated correctly, however I can then see a request being made to ` https://<domain>/_next/data/2PCuD0A4gDEKoTBvZV2Rv/auth/logout.json` which I believe is then logging my user out as when I navigate to other pages my call to `/auth/profile` now returns a `401 Unauthorized`. Is there a step that I’m somehow missing? When running on `localhost` everything seems to be fine it’s just when deployed.

---

<div class="post-metadata">

**Author:** ![teodor.andrei](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/teodor.andrei/32/75320_2.png) [@teodor.andrei](https://community.auth0.com/u/teodor.andrei)\
**Post date:** [April 23, 2025, 1:09pm UTC](https://community.auth0.com/t/nextjs-15-auth0-next-js-4-4-2-login-issues/185785/6 "2025-04-23T13:09:51Z")

</div>

Hi! @tnolan and welcome back to the Auth0 Community!

The snippet you provided seems correct according to the NextJS documentation, so I believe the problem is somewhere else. As a first thing to try, please disable your Actions in the Auth0 dashboard to ensure they don’t interfere, and try again to authenticate a user on the app running on the hosted environment, where the problem occurs.

You have mentioned that this problem started to happen recently. Could you try again on an older version of NextJS? I’m thinking perhaps the version upgrade is not the issue, but another change you have made recently.

Also, could you please check that when you upgraded the NextJS version, you have followed the steps described in [this](https://github.com/auth0/nextjs-auth0/blob/main/V4_MIGRATION_GUIDE.md) migration guide for NextJS 4.x.x?

If none of the above solves your issue, please reproduce the error once again so that we can check the logs in hopes of pinpointing the cause.

Thank you for your post, and don’t hesitate to ask more! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 7, 2025, 1:10pm UTC](https://community.auth0.com/t/nextjs-15-auth0-next-js-4-4-2-login-issues/185785/7 "2025-05-07T13:10:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
