Auth0Client | @auth0/nextjs-auth0 - v4.6.1
Description: Documentation for @auth0/nextjs-auth0

# Class Auth0Client

- Defined in src/server/client.ts:178

##### Index

### Constructors

constructor

### Methods

getAccessToken
getAccessTokenForConnection
getSession
middleware
startInteractiveLogin
updateSession

## Constructors

### constructor

- new Auth0Client(options?: Auth0ClientOptions): Auth0Client

  #### Parameters

  - options: Auth0ClientOptions = {}

  #### Returns Auth0Client

  - Defined in src/server/client.ts:183

## Methods

### getAccessToken

- getAccessToken(
  options?: GetAccessTokenOptions,
  ): Promise<{ expiresAt: number; scope?: string; token: string }>

  #### Parameters

  - `Optional`options: GetAccessTokenOptions

    Optional configuration for getting the access token.

    - ##### refresh

      Force a refresh of the access token.

  #### Returns Promise<{ expiresAt: number; scope?: string; token: string }>

  - Defined in src/server/client.ts:332
- getAccessToken(
  req: NextRequest | PagesRouterRequest,
  res: NextResponse<unknown> | PagesRouterResponse,
  options?: GetAccessTokenOptions,
  ): Promise<{ expiresAt: number; scope?: string; token: string }>

  getAccessToken returns the access token.

  This method can be used in middleware and `getServerSideProps`, API routes in the Pages Router.

  #### Parameters

  - req: NextRequest | PagesRouterRequest

    The request object.

  - res: NextResponse<unknown> | PagesRouterResponse

    The response object.

  - `Optional`options: GetAccessTokenOptions

    Optional configuration for getting the access token.

    - ##### refresh

      Force a refresh of the access token.

  #### Returns Promise<{ expiresAt: number; scope?: string; token: string }>

  - Defined in src/server/client.ts:346

### getAccessTokenForConnection

- getAccessTokenForConnection(
  options: AccessTokenForConnectionOptions,
  ): Promise<{ expiresAt: number; token: string }>

  Retrieves an access token for a connection.

  This method can be used in Server Components, Server Actions, and Route Handlers in the App Router.

  NOTE: Server Components cannot set cookies. Calling `getAccessTokenForConnection()` in a Server Component will cause the access token to be refreshed, if it is expired, and the updated token set will not to be persisted. It is recommended to call `getAccessTokenForConnection(req, res)` in the middleware if you need to retrieve the access token in a Server Component to ensure the updated token set is persisted.

  #### Parameters

  - options: AccessTokenForConnectionOptions

  #### Returns Promise<{ expiresAt: number; token: string }>

  - Defined in src/server/client.ts:451
- getAccessTokenForConnection(
  options: AccessTokenForConnectionOptions,
  req: undefined | NextRequest | PagesRouterRequest,
  res: undefined | NextResponse<unknown> | PagesRouterResponse,
  ): Promise<{ expiresAt: number; token: string }>

  Retrieves an access token for a connection.

  This method can be used in middleware and `getServerSideProps`, API routes in the Pages Router.

  #### Parameters

  - options: AccessTokenForConnectionOptions
  - req: undefined | NextRequest | PagesRouterRequest
  - res: undefined | NextResponse<unknown> | PagesRouterResponse

  #### Returns Promise<{ expiresAt: number; token: string }>

  - Defined in src/server/client.ts:460

### getSession

- getSession(): Promise<null | SessionData>

  getSession returns the session data for the current request.

  This method can be used in Server Components, Server Actions, and Route Handlers in the App Router.

  #### Returns Promise<null | SessionData>

  - Defined in src/server/client.ts:289
- getSession(req: NextRequest | PagesRouterRequest): Promise<null | SessionData>

  getSession returns the session data for the current request.

  This method can be used in middleware and `getServerSideProps`, API routes in the Pages Router.

  #### Parameters

  - req: NextRequest | PagesRouterRequest

  #### Returns Promise<null | SessionData>

  - Defined in src/server/client.ts:296

### middleware

- middleware(req: NextRequest): Promise<NextResponse<unknown>>

  middleware mounts the SDK routes to run as a middleware function.

  #### Parameters

  - req: NextRequest

  #### Returns Promise<NextResponse<unknown>>

  - Defined in src/server/client.ts:280

### startInteractiveLogin

- startInteractiveLogin(
  options: StartInteractiveLoginOptions,
  ): Promise<NextResponse<unknown>>

  #### Parameters

  - options: StartInteractiveLoginOptions

  #### Returns Promise<NextResponse<unknown>>

  - Defined in src/server/client.ts:669

### updateSession

- updateSession(
  req: NextRequest | PagesRouterRequest,
  res: NextResponse<unknown> | PagesRouterResponse,
  session: SessionData,
  ): Promise<void>

  updateSession updates the session of the currently authenticated user. If the user does not have a session, an error is thrown.

  This method can be used in middleware and `getServerSideProps`, API routes, and middleware in the Pages Router.

  #### Parameters

  - req: NextRequest | PagesRouterRequest
  - res: NextResponse<unknown> | PagesRouterResponse
  - session: SessionData

  #### Returns Promise<void>

  - Defined in src/server/client.ts:562
- updateSession(session: SessionData): Promise<void>

  updateSession updates the session of the currently authenticated user. If the user does not have a session, an error is thrown.

  This method can be used in Server Actions and Route Handlers in the App Router.

  #### Parameters

  - session: SessionData

  #### Returns Promise<void>

  - Defined in src/server/client.ts:573