BetterStarter logo
BetterStarter
Docs
GuidesAuth Providers

Twitter (X) Auth

Add Twitter/X OAuth sign-in to your app.

Docs are in beta — content is improving rapidly. Found something missing? Open an issue on GitHub or reach out on Twitter (X).

1. Create a Twitter Developer App

  1. Go to the Twitter Developer Portal

  2. From side menu click on Apps then Create App

  3. Create App:

    • App Name, Environment
    • Click Create New Client Application
  4. Configure:

    • Click on the App you just created
    • Click Settings
    • Type of App: Web App, Automated App or Bot
    • Enable (Request email from users*
    • Put in App Info
      • Callback URI / Redirect URL:
      • http://localhost:3000/api/auth/callback/twitter (dev)
      • https://yourdomain.com/api/auth/callback/twitter (prod)
    • Website URL, Terms URL, Privacy URL, Organization Name, Organization URL
  5. Save, then go to Keys and tokens

  6. Under OAuth 2.0 Client ID and Client Secret, copy both values

2. Set Environment Variables

# .env.local
TWITTER_CLIENT_ID=your-oauth2-client-id
TWITTER_CLIENT_SECRET=your-oauth2-client-secret

3. Enable in Config

In src/appConfig.ts set:

twitter: { enabled: true },

4. Test

  1. Run pnpm dev
  2. Navigate to /auth/sign-in
  3. A Sign in with Twitter button will appear

Production Checklist

  • Add your production callback URL in the Twitter Developer Portal app settings
  • Twitter's free tier may limit OAuth usage — check your plan's rate limits

Troubleshooting

  • No email returned — make sure user.email scope is enabled in your app's user authentication settings
  • unauthorized_client — ensure you're using OAuth 2.0 credentials (not OAuth 1.0a API keys)
  • No Twitter button — check TWITTER_CLIENT_ID and TWITTER_CLIENT_SECRET are set and twitter.enabled is true

On this page