Social login
Users sign in to an application through Twitter/X using Auth.js’s standard provider configuration.
Auth.js · Const
Twitter is a built-in Auth.js OAuth provider. Add it to the providers array, configure its credentials through the standard environment variables, and use its Twitter callback URL.
Twitter is registered as a built-in Auth.js provider by placing it in the providers array. Auth.js now uses Twitter/X OAuth 2.0 by default, while the provider reference also documents an explicit version option for OAuth 2.0 configuration.
function default(config): OAuthConfig<TwitterProfile>| Name | Type | Description |
|---|---|---|
config | OAuthUserConfig<TwitterProfile> | Optional provider configuration, including OAuth client credentials and version settings. |
OAuthConfig<TwitterProfile>
import NextAuth from "next-auth"
import Twitter from "next-auth/providers/twitter"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Twitter],
})Register the Twitter provider in the Auth.js configuration; the provider reads AUTH_TWITTER_ID and AUTH_TWITTER_SECRET automatically.
Users sign in to an application through Twitter/X using Auth.js’s standard provider configuration.
An application uses Auth.js Core and needs a Twitter provider with explicit client credentials.
An adapter-backed application must persist provider-specific OAuth 1.0 token fields.
Add the imported Twitter provider to Auth.js’s providers array. With the current setup, Auth.js can infer the credentials from AUTH_TWITTER_ID and AUTH_TWITTER_SECRET.
Follow-up: How would you opt into OAuth 2.0 explicitly in the core provider configuration? Pass version: "2.0" alongside clientId and clientSecret.
The callback path is /api/auth/callback/twitter for the Next.js-style setup. The provider identifier used by Auth.js is Twitter.
Follow-up: What limitation should be considered when relying on Twitter/X OAuth 2.0? Email is not currently supported by that flow.
The provider reference describes Twitter as the only built-in provider using OAuth 1.0 and says that flow returns oauth_token and oauth_token_secret instead of access_token and refresh_token. Adapter-backed applications should include those values in their database schema.
Follow-up: What application setting is needed to obtain an email address with OAuth 1.0? Enable “Request email address from users” in the application permissions.
TwitterProfileOAuthConfigOAuthUserConfigAuthprovidersAUTH_TWITTER_IDAUTH_TWITTER_SECRET