The main way to use the server SDK.
Page Router
Simply set the environment variables per ConfigParameters then create the file pages/api/auth/[auth0].js. For example:
pages/api/auth/[auth0].js
// pages/api/auth/[auth0].jsimport { handleAuth } from '@auth0/nextjs-auth0';export default handleAuth(); Copy
// pages/api/auth/[auth0].jsimport { handleAuth } from '@auth0/nextjs-auth0';export default handleAuth();
App Router
Simply set the environment variables per ConfigParameters then create the file app/api/auth/[auth0]/route.js. For example:
app/api/auth/[auth0]/route.js
// app/api/auth/[auth0]/route.jsimport { handleAuth } from '@auth0/nextjs-auth0';export const GET = handleAuth(); Copy
// app/api/auth/[auth0]/route.jsimport { handleAuth } from '@auth0/nextjs-auth0';export const GET = handleAuth();
This will create 5 handlers for the following urls:
/api/auth/login
/api/auth/callback
/api/auth/logout
/api/auth/me
Optional
The main way to use the server SDK.
Page Router
Simply set the environment variables per ConfigParameters then create the file
pages/api/auth/[auth0].js
. For example:App Router
Simply set the environment variables per ConfigParameters then create the file
app/api/auth/[auth0]/route.js
. For example:This will create 5 handlers for the following urls:
/api/auth/login
: log the user in to your app by redirecting them to your identity provider./api/auth/callback
: The page that your identity provider will redirect the user back to on login./api/auth/logout
: log the user out of your app./api/auth/me
: View the user profile JSON (used by the UseUser hook).