# Auth0 triggers auth/profile endpoint every few seconds. Is this expected behavior?

**URL:** <https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [May 5, 2025, 11:25pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340 "2025-05-05T23:25:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmaccou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mmaccou/32/71933_2.png) [@mmaccou](https://community.auth0.com/u/mmaccou)\
**Post date:** [May 5, 2025, 11:25pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/1 "2025-05-05T23:25:53Z")

</div>

When I look to see what initiates the call, its the use-user.js hook within the Auth0 code. This is the code:

```auto
"use client";
import useSWR from "swr";
export function useUser() {
    const { data, error, isLoading } = useSWR(process.env.NEXT_PUBLIC_PROFILE_ROUTE || "/auth/profile", (...args) => fetch(...args).then((res) => {
        if (!res.ok) {
            throw new Error("Unauthorized");
        }
        return res.json();
    }));
    // if we have the user loaded via the provider, return it
    if (data) {
        return {
            user: data,
            isLoading: false,
            error: null
        };
    }
    if (error) {
        return {
            user: null,
            isLoading: false,
            error
        };
    }
    return {
        user: data,
        isLoading,
        error
    };
}

```

When I’m logged in it’s not really a problem. But when I’m not, it clogs up my logs with a 404 error. Is this expected behavior? The only thing I can think of is I set up my middleware wrong, but I followed the quick start.

```auto
import { NextRequest } from "next/server"
import { auth0 } from "./lib/auth0"

const GUEST_SECRET = process.env.GUEST_SECRET!
const secret = new TextEncoder().encode(GUEST_SECRET)

export async function middleware(request: NextRequest) {
  const response = await auth0.middleware(request)

  return response
}

export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
  ],
}

```

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [May 7, 2025, 6:03pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/3 "2025-05-07T18:03:36Z")

</div>

Hi @mmaccou

I am sorry about the delayed response to your inquiry!

Basically, if an user is not authenticated in your NextJS application, it should not be throwing 404 errors continually.

Are you redirecting to a proper auth endpoint as mentioned in [this](https://community.auth0.com/t/404-error-when-following-basic-setup-instructions/132231) community post? Also, are you using `loginWithRedirect()` or `loginWithPopup()`? You could try to download our sample app and build upon it or replace parts and see if the behaviour is being reproduced.

Simply, I believe there might be a slight misconfiguration inside your application where it is not using a proper endpoint. You could examine the sample application and compare it with your own personal configuration.

If you have any other questions, let me know!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![mmaccou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mmaccou/32/71933_2.png) [@mmaccou](https://community.auth0.com/u/mmaccou)\
**Post date:** [May 7, 2025, 9:02pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/4 "2025-05-07T21:02:34Z")

</div>

> [@nik.baleca](#):
>
> loginWithRedirect()

Hi Nik,

I’m not using `loginWithRedirect()` or `loginWithPopup()`. I’m I have a button that takes users to [http://localhost:3000/auth/login](http://localhost:3000/auth/login). That works fine. And I double checked my settings and confirmed localhost is included where possible:

 ![Screenshot 2025-05-07 at 1.55.42 PM](https://global.discourse-cdn.com/auth0/original/3X/2/9/2932aa91fff3b3570b232eea174bb8b20366e01d.jpeg)

It’s just the profile endpoint that keeps triggering which I don’t have anywhere in my code. I looked at the link you gave but I don’t see a mention of using a proper endpoint vs an improper one…am I missing something? I also dont see a sample app to clone. The link in your docs [HERE](https://auth0.com/docs/quickstart/webapp/nextjs/interactive) is broken

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [May 9, 2025, 5:14pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/5 "2025-05-09T17:14:23Z")

</div>

Hi again!

I am sorry about the late reply.

Regarding the sample application available on github, you can access it [here](https://github.com/auth0-samples/auth0-nextjs-samples/tree/main/).

Otherwise, I am still investigating the matter and come back with an update as soon as possible!

Kind Regards,  
Nik

---

<div class="post-metadata">

**Author:** ![ell.wir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ell.wir/32/60703_2.png) [@ell.wir](https://community.auth0.com/u/ell.wir)\
**Post date:** [September 10, 2025, 2:19pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/6 "2025-09-10T14:19:40Z")

</div>

Hi!

We’re also seeing the `/auth/profile` endpoint being called every few seconds in our Next application running SDK v4.9.0. We tested with the official sample app as @nik.baleca suggested and observed the same behavior.

It sounds like this isn’t expected behavior, did you find out if there’s a way to configure/disable it @mmaccou?

---

<div class="post-metadata">

**Author:** ![garrett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/garrett/32/72706_2.png) [@garrett](https://community.auth0.com/u/garrett)\
**Post date:** [October 8, 2025, 10:25pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/7 "2025-10-08T22:25:51Z")

</div>

Still no update here? In v3, `/auth/me` was being called once via `useUser()`. If the user was not authenticated, it returned a 204. In v4 `/auth/profile` is being called constantly and returning a 401 if user is not authenticated. Other than the [vague notes about useUser behavior in the docs](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#understanding-useuser-behavior), I don’t see any info on this or how to configure it.

---

<div class="post-metadata">

**Author:** ![garrett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/garrett/32/72706_2.png) [@garrett](https://community.auth0.com/u/garrett)\
**Post date:** [October 9, 2025, 12:06am UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/8 "2025-10-09T00:06:32Z")

</div>

For those who end up here, it’s not documented in any of the guides, but there is a `noContentProfileResponseWhenUnauthenticated` configuration option that defaults to `false`. Setting it to `true` will go back to returning a 204.

> **[Auth0ClientOptions | @auth0/nextjs-auth0 - v4.10.0](https://auth0.github.io/nextjs-auth0/interfaces/types.Auth0ClientOptions.html#nocontentprofileresponsewhenunauthenticated)**
>
> Documentation for @auth0/nextjs-auth0

Still would like input on the constant re-fetching of `/auth/profile` with `useUser()`

---

<div class="post-metadata">

**Author:** ![mmaccou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mmaccou/32/71933_2.png) [@mmaccou](https://community.auth0.com/u/mmaccou)\
**Post date:** [October 9, 2025, 1:03am UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/9 "2025-10-09T01:03:34Z")

</div>

yea id also like some guidance on this. @nik.baleca can you jump in?

---

<div class="post-metadata">

**Author:** ![nik.baleca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nik.baleca/32/68749_2.png) [@nik.baleca](https://community.auth0.com/u/nik.baleca)\
**Post date:** [October 9, 2025, 5:44pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/10 "2025-10-09T17:44:20Z")

</div>

Hi everyone, sorry for the late update on this post!

As far as I have investigated regarding the matter, this might be expected behaviour due to the way the SDK is designed to work with the **App** and **API** routes.

Before going to possible solutions on the matter, to provide more information on the possible causes and on the matter in general.

- The `userUser()` hook relies on the `swr` library in order to fetch user data from the routes defined and it is run whenever a component requests user data
- The SDK typically requires you to create a dynamic or static API route in the `route.ts`. When a user **is not** logged in, the `getSession` function finds no session cookie and often returns a **401 Unauthorized** status.  
\*If the middleware determines the user is not authenticated, it will tipically redirect the user to the login page. However, a client-side data fetch (like SWR) **cannot follow a 302/307 redirect** since it expects a JSON response.

Moving on to the possible solution:

- You can try to create the API route handler that the `useUser` hook is calling. This route will properly handle the unauthenticated state, turning the failed request into a clean `401 Unauthorized` error. You would need to make the necessary changes in the `route.ts` or `profile.ts` files:

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

export async function GET(request: NextRequest) {
  try {
    // checking for the Auth0 session cookie
    const session = await auth0.getSession(request);

    if (!session || !session.user) {
      //Return the 401 error if no session is detected
      return new NextResponse(JSON.stringify({ message: "Unauthorized" }), { 
        status: 401 
      });
    }

    // return user data if user is logged in
    return NextResponse.json(session.user);
  } catch (error) {
    // catch possible 
    return new NextResponse(JSON.stringify({ message: "Internal Server Error" }), {
      status: 500
    });
  }
}

```

- Once your `/auth/profile` route correctly returns a 401 (not a redirect), you can adjust your middleware configuration to exclude the profile route from the general authentication check, letting the dedicated API route handle it:

```auto
export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|auth/profile).*)",
  ],
}

```

Please let me know if the proposed solution works for your environments or if you still experience issues regarding the matter!

Looking forward to your replies!

Kind Regards,  
Nik

---

<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:** [October 31, 2025, 7:52pm UTC](https://community.auth0.com/t/auth0-triggers-auth-profile-endpoint-every-few-seconds-is-this-expected-behavior/186340/11 "2025-10-31T19:52:21Z")

</div>

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