# How to force a log out in a NextJS application?

**URL:** <https://community.auth0.com/t/how-to-force-a-log-out-in-a-nextjs-application/153284>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [November 25, 2024, 11:47am UTC](https://community.auth0.com/t/how-to-force-a-log-out-in-a-nextjs-application/153284 "2024-11-25T11:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimitar10000](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dimitar10000/32/57564_2.png) [@dimitar10000](https://community.auth0.com/u/dimitar10000)\
**Post date:** [November 25, 2024, 11:47am UTC](https://community.auth0.com/t/how-to-force-a-log-out-in-a-nextjs-application/153284/1 "2024-11-25T11:47:43Z")

</div>

Hello, I am trying to make the user log out after having updated their password.  
I have a NextJS app and have followed the quickstart guide, so my “/app/api/auth/[auth0]/route.ts” page is set up like so:

```auto
import { handleAuth,handleProfile,handleLogin, handleLogout } from '@auth0/nextjs-auth0';

const logoutUrl = [
    `${process.env.AUTH0_ISSUER_BASE_URL}/v2/logout?`,
    `client_id=${process.env.AUTH0_CLIENT_ID}`,
    `&returnTo=${process.env.AUTH0_BASE_URL}`,
  ];

export const GET = handleAuth({
    profile: handleProfile({ refetch: true }),
    login: handleLogin({ authorizationParams: {}}),
    logout: handleLogout({returnTo: logoutUrl.join('')}),
    signup: handleLogin({
        authorizationParams: {
          screen_hint: "signup"
        }})
}
);

```

The only way to log out which seems to be working at the moment is by clicking on a link which calls the /api/auth/logout endpoint:

```auto
<Link prefetch={false} href={'/api/auth/logout'}>
                        Log out
</Link>

```

Everything else I’ve tried fails. I need to do it without the user clicking on this link. The user has clicked on a button to save their new password and the log out action needs to be called after that programmatically.

I’ve tried using the Auth0-JS library and this didn’t work:

```auto
webAuth.logout({
  returnTo: 'some url here',
  clientID: 'some client ID here'
});

```

I tried making a fetch request to a route handler too inside the app:

```auto
import { revalidatePath } from 'next/cache'
import {redirect} from 'next/navigation';

export async function GET(req: Request) {
    const domain = process.env.AUTH0_ISSUER_BASE_URL;
    const clientId = process.env.AUTH0_CLIENT_ID;
    const returnTo = process.env.AUTH0_BASE_URL;

    const logoutUrl = `${domain}/v2/logout?client_id=${clientId}&returnTo=${encodeURIComponent(returnTo!)}`;

    revalidatePath(returnTo!);
    redirect(logoutUrl);
  }

```

The user stays logged in still. I also tried redirecting to the link “https://${DOMAIN}/oidc/logout?post\_logout\_redirect\_uri=${process.env.AUTH0\_BASE\_UR L}&client\_id=${CLIENT\_ID}”  
after following this guide:  
[Log Users Out of Auth0 with OIDC Endpoint](https://auth0.com/docs/authenticate/login/logout/log-users-out-of-auth0)

Can someone point me in the right direction as to why only the call to the handleLogout handler from the quickstart setup seems to be logging the user out? Only a link seems to be able to activate it.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 4, 2024, 3:11am UTC](https://community.auth0.com/t/how-to-force-a-log-out-in-a-nextjs-application/153284/3 "2024-12-04T03:11:08Z")

</div>

Hi @dimitar10000,

I have just tested the password reset flow and confirmed that changing passwords invalidates the user’s session. As a result, I was prompted to re-enter my credentials to log in again. This is also mentioned in [this documentation](https://auth0.com/docs/manage-users/sessions#session-use-cases:~:text=Updating%20a%20password%2C%20email%2C%20or%20phone%20number%20also%20causes%20a%20user%27s%20Auth0%20session%20to%20expire.).

Are you not experiencing this behavior?

Thanks,  
Rueben

---

<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:** [December 18, 2024, 3:11am UTC](https://community.auth0.com/t/how-to-force-a-log-out-in-a-nextjs-application/153284/4 "2024-12-18T03:11:13Z")

</div>

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