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:
login
logout
callback
profile
// pages/api/auth/[auth0].jsimport { 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(); } }}); Copy
// pages/api/auth/[auth0].jsimport { 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].jsimport { handleAuth, handleLogin } from '@auth0/nextjs-auth0';export default handleAuth({ login: handleLogin({ authorizationParams: { customParam: 'foo' } // Pass in custom params })}); Copy
// pages/api/auth/[auth0].jsimport { 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].jsimport { handleAuth, handleLogin } from '@auth0/nextjs-auth0';export default handleAuth({ signup: handleLogin({ authorizationParams: { screen_hint: 'signup' } })}); Copy
// pages/api/auth/[auth0].jsimport { handleAuth, handleLogin } from '@auth0/nextjs-auth0';export default handleAuth({ signup: handleLogin({ authorizationParams: { screen_hint: 'signup' } })});
If you want to add some custom behavior to the default auth handlers, you can pass in custom handlers for
login
,logout
,callback
, andprofile
. For example:Alternatively, you can customize the default handlers without overriding them. For example:
You can also create new handlers by customizing the default ones. For example: