HandleCallback: AuthHandler<CallbackOptions>

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

Example

Pass an options object

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

export default handleAuth({
callback: handleCallback({ redirectUri: 'https://example.com' })
});

Example

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

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

export default handleAuth({
callback: handleCallback((req) => {
return { redirectUri: 'https://example.com' };
})
});

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

Example

Override the callback handler

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

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