John
John

Reputation: 11831

How do I avoid redirect to custom IdP logout endpoint when using NextJS Auth0?

I am using the nextjs-auth0 plugin to implement authentication in a NextJS application, where the OIDC IdP I am using is a custom IdP and not Auth0. As such, the logout endpoint on that custom IdP is not enabled.

I am using the API route handler and my /app/api/auth/[auth0]/route.js is currently:

import { handleAuth } from '@auth0/nextjs-auth0';

export const GET = handleAuth();

I have a logout link that calls /app/api/auth/[auth0]/route.js and results in a redirect to my IdP's logout URL which is not enabled, resulting in an error. I want to perform a logout that will clear my session cache and cookies but that will not redirect away from the site.

How do I do override this handleAuth() implementation to do this please?

Upvotes: 0

Views: 82

Answers (1)

Abraham
Abraham

Reputation: 81

Create a file at /app/api/auth/logout/route.ts and expose your custom logout handler there.

Since logout is more specific than [auth0], it takes precedence.

Upvotes: 0

Related Questions