Next.js 14 application with Twitter/X and Google authentication using NextAuth.js.
- Twitter/X OAuth authentication
- Google OAuth authentication
- Session management
- Responsive design with Tailwind CSS
- TypeScript support
- Node.js 18+
- Twitter Developer Account
- Google Cloud Console Account
- Install dependencies:
npm install- Generate NEXTAUTH_SECRET:
openssl rand -base64 32- Create
.env.local:
NEXTAUTH_URL=http://localhost:3003
NEXTAUTH_SECRET=your-generated-secret
# Twitter Keys (OAuth 1.0a)
TWITTER_CLIENT_ID=your-twitter-api-key
TWITTER_CLIENT_SECRET=your-twitter-api-secret
# Google OAuth
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google OAuth:
- Go to "APIs & Services" > "OAuth consent screen"
- Choose "External" user type
- Fill in app name and required fields
- Add test users if needed
- Create credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Web application"
- Add authorized JavaScript origins:
http://localhost:3003 - Add authorized redirect URI:
http://localhost:3003/api/auth/callback/google - Click "Create"
- Copy credentials:
- Use "Client ID" as GOOGLE_CLIENT_ID
- Use "Client Secret" as GOOGLE_CLIENT_SECRET
- Go to Twitter Developer Portal
- Create a new app or select existing
- Setup OAuth 1.0a:
- Go to app settings
- Enable "OAuth 1.0a"
- Set app permissions to "Read and write"
- Add callback URL:
http://localhost:3003/api/auth/callback/twitter - Enable "Request email from users"
- Get API Keys:
- Go to "Keys and tokens" tab
- Under "Consumer Keys" section (OAuth 1.0a):
- Use "API Key" as TWITTER_CLIENT_ID
- Use "API Key Secret" as TWITTER_CLIENT_SECRET
Note: Do not use OAuth 2.0 keys for Twitter. This project uses OAuth 1.0a for better session handling.
Start development server:
npm run devVisit http://localhost:3003
├── app/
│ ├── api/auth/
│ ├── components/
│ ├── layout.tsx
│ ├── page.tsx
│ └── providers.tsx
└── types/
- Next.js 14
- NextAuth.js
- Tailwind CSS
- TypeScript
MIT