Offer Salesforce login in a Next.js application
User sign-in
Auth.js · Const
Auth.js includes Salesforce as a built-in OAuth/OIDC provider. Add it to the provider list, set the Salesforce client credentials, and register the documented callback URL in Salesforce.
Salesforce is a built-in OAuth/OIDC provider. Add the provider to Auth.js, configure the Salesforce client credentials through the documented environment variables, and register Auth.js’s callback URL in Salesforce.
Salesforceimport NextAuth from "next-auth"
import Salesforce from "next-auth/providers/salesforce"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Salesforce],
})Registers Salesforce as a built-in Auth.js provider; credentials are read from the documented environment variables.
User sign-in
Enterprise identity
Multi-provider authentication
Use the built-in Salesforce provider in the Auth.js providers list. In a Next.js setup, import it from next-auth/providers/salesforce and pass Salesforce to NextAuth({ providers: [...] }).
Follow-up: What configuration is needed beyond the provider declaration? Define AUTH_SALESFORCE_ID and AUTH_SALESFORCE_SECRET, then register the correct callback URL with Salesforce.
The documented environment variables are AUTH_SALESFORCE_ID and AUTH_SALESFORCE_SECRET. Auth.js uses these values for the Salesforce client configuration.
Follow-up: How would you customize provider behavior? Call the provider function with options and override the defaults, which Auth.js deeply merges with the built-in configuration.
For Next.js, the callback URL is https://example.com/api/auth/callback/salesforce. This URL must also be entered as the redirect URI in the Salesforce application settings.
Follow-up: What changes for other integrations? The provider page documents /auth/callback/salesforce for Qwik and SvelteKit, while the Next.js path includes /api.
OIDCConfigSalesforceProfilecustomizing a built-in OAuth providerAUTH_SALESFORCE_IDAUTH_SALESFORCE_SECRET