This guide will help you set up and run the demo application that showcases the better-auth-strava package.
- Bun installed (or Node.js 18+)
- Docker and Docker Compose
- A Strava account
- A Strava OAuth application
bun install- Go to Strava API Settings
- Create a new application (or use an existing one)
- Set the Authorization Callback Domain to
localhost - Copy your Client ID and Client Secret
Start the PostgreSQL database using Docker Compose:
docker-compose up -dThis will start a PostgreSQL 16 instance with:
- Host:
localhost:5432 - Database:
better_auth_strava - User:
postgres - Password:
postgres
Verify it's running:
docker ps | grep better-auth-postgresCopy the example environment file:
cd apps/web
cp .env.example .envEdit .env and add your credentials:
# Better Auth Configuration
BETTER_AUTH_SECRET=your-secret-key-here-min-32-chars
BETTER_AUTH_URL=http://localhost:3000
NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3000
# Strava OAuth Credentials
STRAVA_CLIENT_ID=your-strava-client-id
STRAVA_CLIENT_SECRET=your-strava-client-secret
# Database Connection
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/better_auth_stravaGenerate a secure secret:
openssl rand -base64 32Run the migration script to create the necessary tables:
bun run db:migrateThis creates the following tables in PostgreSQL:
user- User accounts and profile datasession- Active user sessionsaccount- OAuth provider connectionsverification- Email verification tokens
bun devThe demo app will be available at http://localhost:3000
The demo application showcases:
- ✅ Sign in with Strava OAuth
- ✅ Automatic token refresh
- ✅ Secure session management
- ✅ Sign out functionality
- ✅ Modern, responsive design
- ✅ Dark mode support
- ✅ Shadcn UI components
- ✅ User profile display
- ✅ Athlete data from Strava
- ✅ Next.js 15 App Router
- ✅ PostgreSQL database
- ✅ Type-safe API routes
- ✅ Server-side session handling
- ✅ Client-side React hooks
apps/web/
├── app/
│ ├── api/auth/[...all]/
│ │ └── route.ts # Better Auth API handler
│ ├── page.tsx # Home page with auth UI
│ ├── layout.tsx # Root layout with providers
│ └── globals.css # Global styles
├── lib/
│ ├── auth.ts # Better Auth server config
│ ├── auth-client.ts # Better Auth client utilities
│ └── db.ts # Database connection
├── components/
│ └── ui/ # Shadcn UI components
└── .env # Environment variables (not in git)
Problem: Cannot connect to PostgreSQL
# Check if container is running
docker ps
# View container logs
docker logs better-auth-postgres
# Restart the container
docker-compose restartProblem: Port 5432 or 3000 already in use
# For PostgreSQL (port 5432)
# Stop other PostgreSQL instances or change port in docker-compose.yml
# For Next.js (port 3000)
# Change port: bun dev --port 3001Problem: Database migration fails
# Reset database
docker-compose down -v
docker-compose up -d
# Wait for PostgreSQL to be ready
sleep 5
# Run migration again
bun run db:migrateProblem: Redirect URI mismatch
- Check your Strava app settings at https://www.strava.com/settings/api
- Ensure Authorization Callback Domain is set to
localhost - Restart the dev server after changing OAuth settings
Problem: Invalid client credentials
- Verify
STRAVA_CLIENT_IDandSTRAVA_CLIENT_SECRETin.env - Ensure no extra spaces or quotes
- Regenerate credentials in Strava if needed
Problem: Session not persisting
- Check
BETTER_AUTH_SECRETis set and at least 32 characters - Clear browser cookies and localStorage
- Restart the development server
docker exec -it better-auth-postgres psql -U postgres -d better_auth_strava\dt -- List all tables
\d user -- Describe user table
SELECT * FROM "user"; -- View all users
SELECT * FROM session; -- View all sessions# Stop and remove containers with volumes
docker-compose down -v
# Start fresh
docker-compose up -d
# Re-run migrations
bun run db:migrateThe demo uses Turbo for fast hot reload. Changes to:
- React components → Instant refresh
- API routes → Requires page refresh
- Environment variables → Requires server restart
Enable debug logging in apps/web/lib/auth.ts:
export const auth = betterAuth({
// ... other config
logger: {
level: "debug",
},
});Modify scopes in apps/web/lib/auth.ts:
socialProviders: {
strava: {
clientId: process.env.STRAVA_CLIENT_ID!,
clientSecret: process.env.STRAVA_CLIENT_SECRET!,
scopes: ["read", "activity:read_all"], // Customize here
},
},After changing scopes:
- Sign out from the demo
- Restart the server
- Sign in again to reauthorize with new scopes
Press Ctrl+C in the terminal running bun dev
# Stop but keep data
docker-compose stop
# Stop and remove (keeps volumes)
docker-compose down
# Stop and remove everything including data
docker-compose down -v- Explore the main README for usage examples
- Check out the package documentation
- Read Better Auth docs for advanced features
- Review Strava API docs for available data
- Check Better Auth Documentation
- Open an issue at GitHub Issues
- Review Strava API Documentation