Handlers: ApiHandlers | ErrorHandlers

If you want to add some custom behavior to the default auth handlers, you can pass in custom handlers for login, logout, callback, and profile. For example:

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

export default handleAuth({
async login(req, res) {
try {
// Pass in custom params to your handler
await handleLogin(req, res, { authorizationParams: { customParam: 'foo' } });
// Add your own custom logging.
logger('Redirecting to login');
} catch (error) {
// Add you own custom error logging.
errorReporter(error);
res.status(error.status || 500).end();
}
}
});

Alternatively, you can customize the default handlers without overriding them. For example:

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

export default handleAuth({
login: handleLogin({
authorizationParams: { customParam: 'foo' } // Pass in custom params
})
});

You can also create new handlers by customizing the default ones. For example:

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

export default handleAuth({
signup: handleLogin({
authorizationParams: { screen_hint: 'signup' }
})
});