Authentication Setup Guide
Complete guide for setting up all authentication methods in TinyKit Pro.
Complete guide for setting up all authentication methods in TinyKit Pro.
Overview
TinyKit Pro supports multiple authentication methods:
- Email/Password authentication - Traditional username/password with JWT tokens
- Magic link (email-based) authentication - Passwordless email links
- OAuth providers - GitHub, Google, Apple
Prerequisites
Before setting up authentication, ensure you have:
- A Convex project with environment variable access
- A Resend account for email functionality (required for password reset and magic links)
- OAuth app credentials for any providers you want to enable
Step 1: Configure Better Auth Secret
Better Auth requires a secret key for signing tokens.
Generate Secret
Run this command to generate a secure secret:
openssl rand -base64 32Add Secret to Convex
Option A: Via Dashboard
- Go to https://dashboard.convex.dev
- Navigate to your project's Settings > Environment Variables
- Add
BETTER_AUTH_SECRETwith the generated value - Add
SITE_URLwith your site URL (e.g.,http://localhost:3000for development)
Option B: Via CLI
npx convex env set BETTER_AUTH_SECRET <your-generated-secret>
npx convex env set SITE_URL http://localhost:3000Both approaches are equivalent - use whichever you prefer.
Step 2: Configure Email Services
Email functionality (password reset, magic links) requires RESEND_API_KEY in the Convex environment:
# Add to Convex environment
npx convex env set RESEND_API_KEY re_your_api_key_hereNote: RESEND_API_KEY is set in Convex environment only—not in .env.local. Both auth emails and notification emails use the Convex backend.
Email configuration (support email, domain, site name) is managed via Admin Panel → Site Settings → Email Configuration.
See Environment Variables Reference for complete configuration.
Step 3: Configure OAuth Providers (Optional)
Authentication providers are automatically enabled when their credentials are set in Convex environment variables. No frontend configuration is needed.
GitHub OAuth
- Create a GitHub OAuth App at https://github.com/settings/applications/new
- Set callback URL:
https://[your-deployment].convex.site/api/auth/callback/github - Add to Convex environment variables:
npx convex env set GITHUB_CLIENT_ID your_github_client_id npx convex env set GITHUB_CLIENT_SECRET your_github_client_secret
Google OAuth
- Create OAuth 2.0 credentials in Google Cloud Console
- Set authorized redirect URI:
https://[your-deployment].convex.site/api/auth/callback/google - Add to Convex environment variables:
npx convex env set GOOGLE_CLIENT_ID your_google_client_id npx convex env set GOOGLE_CLIENT_SECRET your_google_client_secret
Apple OAuth
- Create an Apple Sign In service
- Configure redirect URL:
https://[your-deployment].convex.site/api/auth/callback/apple - Add to Convex environment variables:
npx convex env set AUTH_APPLE_ID your_apple_service_id npx convex env set AUTH_APPLE_SECRET your_apple_private_key
Step 4: Testing Authentication
Start Development Server
bun devTest Authentication Methods
Navigate to http://localhost:3000/auth/sign-in and test each enabled method:
-
Password Authentication
- Use the sign-up page to create an account
- Sign in with email/password
-
Magic Link
- Enter your email to receive a sign-in link
- Click the link to authenticate
-
OAuth Providers
- Click the provider button to authenticate
- Complete OAuth flow
Password Requirements
When password authentication is enabled, passwords must meet these requirements:
- At least 8 characters long
- Contains at least one uppercase letter
- Contains at least one lowercase letter
- Contains at least one number
Authentication Routes
- Sign In:
/auth/sign-in - Sign Up:
/auth/sign-up(only available when password auth is enabled) - Password Reset:
/auth/reset-password
Troubleshooting
"Missing environment variables" error
- Ensure all required environment variables are set in both
.env.localand Convex dashboard - For Better Auth,
BETTER_AUTH_SECRETmust be set in Convex dashboard
OAuth redirect errors
- Verify callback URLs match exactly in both provider settings and Convex configuration
- Check that OAuth client ID and secret are correctly set in Convex environment variables
Magic link not sending
- Verify
RESEND_API_KEYis set in Convex environment variables - Check Resend dashboard for API key status and sending limits
Password reset emails not working
- Verify all required configuration:
RESEND_API_KEY: Valid Resend API key in Convex environment (npx convex env set RESEND_API_KEY re_...)- Email settings configured in admin panel ("Site Settings → Email Configuration")
- Check: Support Email, Support Email Name, Resend Domain, Site URL
Security Notes
- Never commit
.env.localor any file containing secrets to version control - Keep
BETTER_AUTH_SECRETsecure - it's used to sign authentication tokens - Regularly rotate OAuth client secrets and API keys
- Use strong password requirements in production environments