Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Auth.js · Const

Facebook

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.

How it works

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.

Syntax

Facebook

Key points

  • For Next.js, register the Facebook redirect endpoint at the application origin plus /api/auth/callback/facebook.
  • The documented environment variables are AUTH_FACEBOOK_ID for the App ID and AUTH_FACEBOOK_SECRET for the App Secret.
  • The Next.js integration imports Facebook from the next-auth/providers/facebook module.
  • The provider’s clientId is the Facebook App ID, while clientSecret is the Facebook App Secret.

Common mistakes

  • Production deployments cannot use localhost callback URLs; use a separate Facebook development application when testing locally.
  • Do not assume every Facebook profile includes an email address, particularly accounts created on mobile.

Example: Configure Facebook authentication

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.

When to use it

Social sign-in

Users sign in to a Next.js application with their Facebook accounts.

Local development

A development team tests Facebook OAuth locally without affecting production credentials.

Multi-provider authentication

An application supports multiple OAuth providers through one Auth.js configuration.

Interview questions

QHow do you add Facebook authentication to a Next.js Auth.js application?

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.

QWhich environment variables configure the Facebook provider?

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.

QWhat callback URL should be registered for Facebook?

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 Providers
  • Configuring an OAuth provider
  • Callback URL
  • AUTH_FACEBOOK_ID
  • AUTH_FACEBOOK_SECRET

Source: Facebook Provider. Checked 2026-10-15.