Authentication
Configure Better Auth, social login, and role-based access control
Authentication
LaunchSaaS uses Better Auth for authentication, providing a flexible and secure system with multiple authentication methods, session management, and role-based access control.
Setup
1. Generate Better Auth Secret
The BETTER_AUTH_SECRET is a random string used for encryption and generating hashes. Generate one using VictoryHub or run:
openssl rand -base64 32Add it to your .env file:
BETTER_AUTH_SECRET="your-generated-secret-key"2. Configure Magic Link (Optional)
To enable passwordless magic link authentication:
NEXT_PUBLIC_MAGIC_LINK_ENABLED=trueMagic link requires email configuration. See the Email Setup guide.
3. Configure GitHub OAuth (Optional)
- Go to GitHub Developer Settings
- Click on "OAuth Apps" → "New OAuth App"
- Fill in the registration form:
- Application name: Your app name
- Homepage URL:
http://localhost:3000(or your production URL) - Authorization callback URL:
http://localhost:3000/api/auth/callback/github
- Click "Register application"
- Generate a client secret
- Add to your
.envfile:
NEXT_PUBLIC_GITHUB_CLIENT_ID="your-client-id"
GITHUB_CLIENT_SECRET="your-client-secret"Create separate OAuth apps for development and production environments. They require different callback URLs.
4. Configure Google OAuth (Optional)
- Go to Google Cloud Console
- Create a new project or select an existing one
- Go to
Credentials→Create Credentials→OAuth client ID - Configure OAuth consent screen if prompted
- Create OAuth Client ID:
- Application type: Web application
- Authorized JavaScript origins:
http://localhost:3000 - Authorized redirect URIs:
http://localhost:3000/api/auth/callback/google
- Add to your
.envfile:
NEXT_PUBLIC_GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-client-secret"If you are setting up the environment, now you can go back to the Environment Setup guide and continue.
Features
LaunchSaaS authentication includes:
- Email/Password - Traditional signup and login with email verification
- Social Login - Google and GitHub OAuth
- Magic Links - Passwordless authentication
- Password Reset - Secure password recovery
- Session Management - Server-side session handling
- Role-Based Access - User and admin roles
- Stripe Integration - Automatic customer creation
User Roles
User Role
Default role for all registered users. Has access to:
- User dashboard (
/dashboard) - Profile management
- Subscription management
Admin Role
Elevated privileges for administrators. Has access to:
- Admin panel (
/admin) - User management
- All user features
Production Checklist
Before going to production, ensure:
-
BETTER_AUTH_SECRETis a strong, unique secret -
NEXT_PUBLIC_APP_URLis set to your production domain - Social OAuth apps are configured with production callback URLs
- Email service is configured and domain verified