Options
All
  • Public
  • Public/Protected
  • All
Menu

Module handlers/callback

Index

Server Interfaces

Server Type aliases

Server Type aliases

AfterCallback

AfterCallback: (req: NextApiRequest, res: NextApiResponse, session: default, state: {}) => Promise<default> | default

Use this function for validating additional claims on the user's ID Token or adding removing items from the session after login, eg

Validate additional claims

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

const afterCallback = (req, res, session, state) => {
  if (!session.user.isAdmin) {
    throw new UnauthorizedError('User is not admin');
  }
  return session;
};

export default handleAuth({
  async callback(req, res) {
    try {
      await handleCallback(req, res, { afterCallback });
    } catch (error) {
      res.status(error.status || 500).end(error.message);
    }
  }
});

Modify the session after login

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

const afterCallback = (req, res, session, state) => {
  session.user.customProperty = 'foo';
  delete session.refreshToken;
  return session;
};

export default handleAuth({
  async callback(req, res) {
    try {
      await handleCallback(req, res, { afterCallback });
    } catch (error) {
      res.status(error.status || 500).end(error.message);
    }
  }
});
throws

HandlerError

Type declaration

    • Parameters

      • req: NextApiRequest
      • res: NextApiResponse
      • session: default
      • state: {}
        • [key: string]: any

      Returns Promise<default> | default

HandleCallback

HandleCallback: (req: NextApiRequest, res: NextApiResponse, options?: CallbackOptions) => Promise<void>

The handler for the api/auth/callback route.

throws

HandlerError

Type declaration

    • (req: NextApiRequest, res: NextApiResponse, options?: CallbackOptions): Promise<void>
    • Parameters

      • req: NextApiRequest
      • res: NextApiResponse
      • Optional options: CallbackOptions

      Returns Promise<void>