Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
Getting Started
Providers
Twitter

Twitter Provider

Resources

Setup

Callback URL

https://example.com/api/auth/callback/twitter

Environment Variables

AUTH_TWITTER_ID
AUTH_TWITTER_SECRET

Configuration

/auth.ts
import NextAuth from "next-auth"
import Twitter from "next-auth/providers/twitter"
 
export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [Twitter],
})

To enable OAuth 2.0, simply add version: “2.0” to your Provider configuration.

./auth.ts
Twitter({
  clientId: process.env.TWITTER_ID,
  clientSecret: process.env.TWITTER_SECRET,
  version: "2.0", // opt-in to Twitter OAuth 2.0
})

Notes

  • Email is currently not supported by Twitter OAuth 2.0.
  • You must enable the “Request email address from users” option in your app permissions if you want to obtain the users email address.
Auth.js © Balázs Orbán and Team - 2024