Creates a configured Fetcher instance for making authenticated API requests.
This method creates a specialized HTTP client that handles:
The fetcher provides a high-level interface for making requests to protected resources without manually handling authentication details.
Response type that extends the standard Response interface
Request object for session context (required for Pages Router, optional for App Router)
Configuration options for the fetcher
Optional
baseUrl?: stringBase URL for relative requests. Must be provided if using relative URLs
Optional
fetch?: CustomFetchImpl<TOutput>Custom fetch implementation. Falls back to global fetch if not provided
Optional
getAccessToken?: AccessTokenFactoryCustom access token factory function. If not provided, uses the default from hooks
Optional
nonceStorageId?: stringOptional
useDPoP?: booleanEnable DPoP for this fetcher instance (overrides global setting)
Promise that resolves to a configured Fetcher instance
Optional
options: GetAccessTokenOptionsOptional configuration for getting the access token.
Optional
audience?: string | nullPlease note: If you are passing audience, ensure that the used audiences and scopes are part of the Application's Refresh Token Policies in Auth0 when configuring Multi-Resource Refresh Tokens (MRRT). Auth0 Documentation on Multi-resource Refresh Tokens
Optional
refresh?: boolean | nullOptional
scope?: string | nullgetAccessToken returns the access token.
This method can be used in middleware and getServerSideProps
, API routes in the Pages Router.
The request object.
The response object.
Optional
options: GetAccessTokenOptionsOptional configuration for getting the access token.
Optional
audience?: string | nullPlease note: If you are passing audience, ensure that the used audiences and scopes are part of the Application's Refresh Token Policies in Auth0 when configuring Multi-Resource Refresh Tokens (MRRT). Auth0 Documentation on Multi-resource Refresh Tokens
Optional
refresh?: boolean | nullOptional
scope?: string | nullRetrieves 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.
Retrieves an access token for a connection.
This method can be used in middleware and getServerSideProps
, API routes in the Pages Router.
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.
getSession returns the session data for the current request.
This method can be used in middleware and getServerSideProps
, API routes in the Pages Router.
Authenticates using Client-Initiated Backchannel Authentication and returns the token set and optionally the ID token claims and authorization details.
This method will initialize the backchannel authentication process with Auth0, and poll the token endpoint until the authentication is complete.
Using Client-Initiated Backchannel Authentication requires the feature to be enabled in the Auth0 dashboard.
middleware mounts the SDK routes to run as a middleware function.
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.
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.
Optional
fnOrOpts: AppRouterPageRoute | WithPageAuthRequiredPageRouterOptionsOptional
opts: WithPageAuthRequiredAppRouterOptions
Initiates the Connect Account flow to connect a third-party account to the user's profile. If the user does not have an active session, a
ConnectAccountError
is thrown.This method first attempts to obtain an access token with the
create:me:connected_accounts
scope for the My Account API to create a connected account for the user.The user will then be redirected to authorize the connection with the third-party provider.