Better Auth
This project usesbetter-auth for its hybrid authentication system, providing both email/password authentication and social OAuth providers (currently Google).
Instead of duplicating extensive documentation, this guide provides links to the official resources. Please refer to them for detailed setup, configuration, and API usage.
Key Resources
When working on authentication-related tasks, always refer to these official documents to ensure you are following the correct patterns and security best practices:-
Convex & Svelte Adapter: This project uses a specific adapter for integrating
better-authwith Convex and SvelteKit. The README for this adapter is a crucial resource. -
Official Documentation: The primary source for all
better-authconcepts, API, and guides. - Email Authentication Concepts: For a deep dive into how email/password authentication is handled.
- Admin Plugin: Documentation for the admin plugin functionality.
- Google OAuth: Documentation for setting up Google Sign-In.
Google OAuth Setup
This project has Google OAuth pre-configured. To enable it:1. Create Google OAuth Credentials
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to “APIs & Services” > “Credentials”
- Click “Create Credentials” > “OAuth client ID”
- Choose “Web application” as the application type
- Add authorized redirect URIs:
- For development:
http://localhost:5173/api/auth/callback/google - For production:
https://yourdomain.com/api/auth/callback/google
- For development:
- Copy the Client ID and Client Secret
2. Set Environment Variables
3. Update Authorized Redirect URIs
Make sure your redirect URI follows this pattern:- Development:
http://localhost:5173/api/auth/callback/google - Production:
https://yourdomain.com/api/auth/callback/google
/api/auth/callback/google is handled automatically by Better Auth through the SvelteKit API route.
4. How It Works
The Google OAuth flow is already implemented in:- Server:
src/convex/auth.ts- Contains the Google OAuth configuration insocialProviders - Client:
src/lib/auth-client.ts- No additional plugin needed; social auth is built-in - UI:
src/lib/components/login-form.svelte- Has the “Login with Google” button
GitHub OAuth Setup
This project has GitHub OAuth pre-configured for both authentication and automatic integration setup.1. Create GitHub OAuth App
- Go to GitHub Developer Settings
- Click “New OAuth App”
- Fill in the application details:
- Application name: Dashtray (or your app name)
- Homepage URL:
- Development:
http://localhost:5173 - Production:
https://yourdomain.com
- Development:
- Authorization callback URL:
- Development:
http://localhost:5173/api/auth/callback/github - Production:
https://yourdomain.com/api/auth/callback/github
- Development:
- Click “Register application”
- Copy the Client ID
- Click “Generate a new client secret” and copy it
2. Set Environment Variables
3. How It Works
The GitHub OAuth flow is implemented in:- Server:
src/convex/auth.ts- Contains the GitHub OAuth configuration insocialProviders - Client:
src/lib/auth-client.ts- Social auth is built-in - UI:
src/lib/components/login-form.svelte- Has the “Sign in with GitHub” button
4. Automatic Integration Connection
When a user signs in with GitHub, the system automatically:- Creates a GitHub integration connection for their default project
- Uses the OAuth access token for API calls
- Starts syncing repository metrics immediately
5. Token Permissions
The GitHub OAuth app requests these scopes:repo- Access to repositories (public and private)read:user- Read user profile informationuser:email- Access to user email addresses
- Fetch repository metrics (commits, PRs, issues, stars, forks)
- Access both public and private repositories
- Display user information in the dashboard