NextAuth with Pages Router
This guide will help you integrate Descope with your NextAuth application using the Pages Router. Follow the steps below to get started.
If you're interested in using our native SDK instead of NextAuth, you can read about the pros and cons of each in our guide.
Install NextAuth.js
To use Descope with Next.js, the simplest method is to use NextAuth.js. You can install it with this command:
Import NextAuth Packages
Import all necessary NextAuth packages in a [...nextauth].ts
file. The location of [...nextauth].ts
will exist in pages/api/auth
.
Initialize Descope as a Provider
Once you've imported the necessary packages, you'll need to initialize NextAuth and add Descope as a provider.
Setup NextAuth's SessionProvider
In your _app.tsx
file, wrap the components in SessionProvider
to allow for session management and authentication throughout your Next application.
Accessing the Authentication Flow
Add a sign-in button in the client to access your sign-in authentication flow. The signIn
method has 'descope' as the provider id, and the callback URL set to /dashboard
as an example to redirect back to.
Session Management
To learn more about session management with NextAuth & Descope, check out the Web Client Session Validation docs.
Congratulations
Now that you've got the authentication down, go focus on building out the rest of your app!
Checkpoint
Your application is now integrated with Descope. Please test with sign-up or sign-in use case.
Using NextAuth and Customization
Once you've configured NextAuth to work with Descope as an OIDC provider, the next step is to utilize all of the various NextAuth functions in your application.
You can visit our guide with detailed docs on how all of the Sign In
, Logout
, etc. functions work with NextAuth, in your Next.js application.
Otherwise, you can visit our Flow Customization section to configure and personalize many different areas of Descope, including your brand, style, custom user authentication journeys, etc.
We recommend starting with customizing your user-facing screens, such as signup and login.