Skip to content

User Authentication with Twitter OAuth 2.0

LaunchFa.st uses in house simple as heck server-side first Twitter OAuth 2.0 to help you authenticate users via Twitter.

You can configure it in the src/pages/api/auth/twitter.js and src/pages/api/auth/callback/twitter.js file.
  1. Update the .env file or hosting provider’s environment variable to have the necessary variables for Twitter OAuth 2.0:
# Obtained from Twitter APIs
# https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code

TWITTER_CLIENT_ID="..."
TWITTER_CLIENT_SECRET="..."

# Based on your domain
TWITTER_AUTH_CALLBACK_URL="https://your-domain.com/api/auth/callback/twitter"
  1. To simply authenticate users via Twitter, import the Sign-In-With-Twitter component in each framework as described below:
---
// File: src/pages/file.astro

import SignInWithTwitter from '@/components/Sign-In-With-Twitter.astro'
---

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
  </head>
  <body>
    <SignInWithTwitter />
  </body>
</html>