Add Netlify as a sign-in option
Next.js application
Auth.js · Const
Auth.js includes a built-in Netlify OAuth provider. Register it in the provider list and configure the Netlify client credentials through the documented environment variables or provider options.
The built-in Netlify provider is added to the Auth.js provider list. In a Next.js application, the provider can use AUTH_NETLIFY_ID and AUTH_NETLIFY_SECRET automatically, while the OAuth callback must point to the documented callback path.
function default(config): OAuthConfig<Record<string, any>>| Name | Type | Description |
|---|---|---|
config | OAuthUserConfig<Record<string, any>> | Optional OAuth provider configuration, including client credentials or overrides. |
OAuthConfig<Record<string, any>>
import NextAuth from "next-auth"
import Netlify from "next-auth/providers/netlify"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Netlify],
})Register the built-in Netlify provider in a NextAuth configuration; Auth.js reads the provider credentials from the documented environment variables.
Next.js application
OAuth configuration
Custom OAuth setup
Use the built-in Netlify provider in the providers array. In Next.js, import it from next-auth/providers/netlify and register it as Netlify.
Follow-up: What credentials are needed? Set AUTH_NETLIFY_ID and AUTH_NETLIFY_SECRET, or provide equivalent client credentials when configuring the provider.
The callback URL is https://example.com/api/auth/callback/netlify for Next.js applications. Replace the domain with the deployed application's domain.
Follow-up: How does the callback differ outside Next.js? Other documented frameworks use /auth/callback/netlify by default.
Netlify is treated as an OAuth 2 provider with built-in defaults. The provider function accepts an OAuthUserConfig<Record<string, any>> and returns an OAuthConfig<Record<string, any>>.
Follow-up: When should the defaults be changed? Pass a configuration object to the provider when the application's OAuth setup needs values different from the built-in configuration.
OAuthConfigOAuthUserConfigcustomizing a built-in OAuth providerAUTH_NETLIFY_IDAUTH_NETLIFY_SECRET