Social sign-in
Users sign in to a Next.js application with their Facebook accounts.
Auth.js · Const
Auth.js’s Facebook provider adds Facebook OAuth sign-in to an application. Configure it with the Facebook App ID and App Secret, then register the provider-specific callback URL.
Facebook is enabled by adding the imported provider to Auth.js’s providers list. Auth.js uses the Facebook App ID and App Secret through environment variables, and Facebook sends users back to the provider-specific callback URL.
Facebook/api/auth/callback/facebook.AUTH_FACEBOOK_ID for the App ID and AUTH_FACEBOOK_SECRET for the App Secret.next-auth/providers/facebook module.clientId is the Facebook App ID, while clientSecret is the Facebook App Secret.import NextAuth from "next-auth"
import Facebook from "next-auth/providers/facebook"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Facebook],
})Register the Facebook provider in the Auth.js configuration; credentials are read from the documented environment variables.
Users sign in to a Next.js application with their Facebook accounts.
A development team tests Facebook OAuth locally without affecting production credentials.
An application supports multiple OAuth providers through one Auth.js configuration.
Import the Facebook provider from the framework-specific Auth.js package and include it in the providers array passed to the Auth.js configuration. For Next.js, the documented setup uses NextAuth from next-auth and Facebook from next-auth/providers/facebook.
Follow-up: What callback URL must Facebook be configured to use? Use the application’s base URL followed by /api/auth/callback/facebook for Next.js.
Set AUTH_FACEBOOK_ID to the Facebook App ID and AUTH_FACEBOOK_SECRET to the Facebook App Secret. Auth.js maps these environment variables to the provider credentials.
Follow-up: Which credential names correspond to these values? The provider configuration calls them clientId and clientSecret.
The Facebook callback endpoint is https://example.com/api/auth/callback/facebook in the Next.js example. The callback path includes the provider identifier, facebook.
Follow-up: What local-development restriction applies? A production Facebook application cannot use localhost callback URLs; use a dedicated development application instead.
OAuth ProvidersConfiguring an OAuth providerCallback URLAUTH_FACEBOOK_IDAUTH_FACEBOOK_SECRET