HandleLogout: AuthHandler<LogoutOptions>

Use this to customize the default logout handler without overriding it. You can still override the handler if needed.

Example

Pass an options object

// pages/api/auth/[auth0].js
import { handleAuth, handleLogout } from '@auth0/nextjs-auth0';

export default handleAuth({
logout: handleLogout({ returnTo: 'https://example.com' })
});

Example

Pass a function that receives the request and returns an options object

// pages/api/auth/[auth0].js
import { handleAuth, handleLogout } from '@auth0/nextjs-auth0';

export default handleAuth({
logout: handleLogout((req) => {
return { returnTo: 'https://example.com' };
})
});

This is useful for generating options that depend on values from the request.

Example

Override the logout handler

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

export default handleAuth({
logout: async (req, res) => {
try {
await handleLogout(req, res, {
returnTo: 'https://example.com'
});
} catch (error) {
console.error(error);
}
}
});