Overview
Add social authentication to your TanStack Start app with support for GitHub and Google OAuth. Built on Convex Auth with automatic user profile creation, session management, and protected routes.Features
- GitHub OAuth integration
- Google OAuth integration
- Automatic user profile creation
- Profile pictures from OAuth providers
- Session management
- Protected routes
- Loading states
- Error handling
- Type-safe
Installation
Configure OAuth providers
Set up OAuth apps in provider dashboards:GitHub:
- Go to GitHub Settings → Developer settings → OAuth Apps
- Create new OAuth app
- Set callback URL:
https://YOUR_CONVEX_URL/api/auth/callback/github
- Go to Google Cloud Console → APIs & Services → Credentials
- Create OAuth 2.0 Client ID
- Add authorized redirect URI:
https://YOUR_CONVEX_URL/api/auth/callback/google
What Gets Installed
Components
login-form.tsx- Social login buttons for GitHub and Googlelogout-button.tsx- Sign out button
Routes
routes/auth/login.tsx- Login page with social optionsroutes/_protected/index.tsx- Example protected route
Backend (Convex)
convex/schema.ts- User schema with OAuth fieldsconvex/auth.ts- Auth query endpointsconvex/auth.config.ts- OAuth provider configurationconvex/users.ts- User profile queriesconvex/http.ts- OAuth callback handlers
Environment Variables
Required (Convex Dashboard)
GitHub OAuth App Client ID
GitHub OAuth App Client Secret
Google OAuth Client ID
Google OAuth Client Secret
At least one OAuth provider (GitHub or Google) must be configured for authentication to work.
Usage
Basic Social Login
routes/auth/login.tsx
Specify Providers
Choose which OAuth providers to display:Protected Routes
Check authentication before rendering protected content:routes/_protected.tsx
Display User Info
Access authenticated user data:Sign Out
OAuth Flow
API Reference
SocialLoginForm Props
Array of OAuth providers to display. Available options:
"github", "google"Auth Actions
Use Convex Auth hooks for programmatic authentication:Check Auth Status
Backend Implementation
User Schema
OAuth providers populate these fields:convex/schema.ts
User Queries
Access user data securely:convex/users.ts
Customization
Custom Button Styles
Modify the login form component:Add More Providers
Convex Auth supports additional OAuth providers. Updateconvex/auth.config.ts:
Custom Redirect
Change where users go after login:Getting OAuth Credentials
GitHub
Fill in Details
- Application name: Your app name
- Homepage URL: Your app URL
- Callback URL:
https://YOUR_CONVEX_URL/api/auth/callback/github
Go to Google Cloud Console
Visit Google Cloud Console
Security
- OAuth tokens are never exposed to the client
- Callback URLs must be configured in provider dashboards
- State parameter prevents CSRF attacks
- Sessions are HTTP-only cookies
- Tokens expire automatically
Troubleshooting
Redirect URI mismatch
Redirect URI mismatch
Ensure the callback URL in your OAuth provider settings exactly matches:
https://YOUR_CONVEX_URL/api/auth/callback/{provider}Cannot read properties of undefined (reading 'signIn')
Cannot read properties of undefined (reading 'signIn')
Make sure your app is wrapped with
ConvexClientProvider.OAuth provider not configured
OAuth provider not configured
Verify environment variables are set in the Convex dashboard, not your local
.env file.User data not showing
User data not showing
Check that your OAuth app has permissions to access user email and profile.
Related Components
- Password-Based Auth - Add email/password authentication
- Current User Avatar - Display authenticated user
- Convex Client Setup - Configure Convex with TanStack Start