Overview
AniDojo uses Supabase Auth for user authentication, supporting email/password login, magic links, and social providers. Authentication is integrated with automatic profile creation and session management.Email Authentication
Email authentication is enabled by default in Supabase.Configure Email Settings
Enable Email provider
Ensure Email is enabled (it should be by default)Options:
- ✅ Email confirmation - Require email verification
- ✅ Secure password - Enforce password requirements
- Minimum password length: 8 characters (recommended)
Email Templates
Customize the emails sent to users for various auth events.Available Templates
Navigate to Authentication → Email Templates to customize:Confirm Signup
Confirm Signup
Sent when a new user signs up.Default Subject:
Confirm your emailVariables:{{ .ConfirmationURL }}- Email confirmation link{{ .Token }}- Confirmation token{{ .Email }}- User’s email address
Invite User
Invite User
Sent when inviting a user to join.Variables:
{{ .ConfirmationURL }}- Invitation acceptance link{{ .Email }}- Invited user’s email
Magic Link
Magic Link
Sent for passwordless login.Variables:
{{ .ConfirmationURL }}- Magic link URL{{ .Token }}- Login token
Reset Password
Reset Password
Sent when user requests password reset.Variables:
{{ .ConfirmationURL }}- Password reset link{{ .Token }}- Reset token
Change Email
Change Email
Sent when user changes their email.Variables:
{{ .ConfirmationURL }}- Email change confirmation link{{ .NewEmail }}- New email address{{ .Email }}- Old email address
Example Custom Template
Social Authentication (Optional)
Enable login with Google, GitHub, Discord, and more.Enable Google OAuth
Create Google OAuth app
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
Configure OAuth consent
- Application type: Web application
- Authorized redirect URIs:
Enable GitHub OAuth
Create GitHub OAuth app
- Go to GitHub Developer Settings
- Click New OAuth App
- Fill in:
- Application name: AniDojo
- Homepage URL: Your app URL
- Authorization callback URL:
Other Providers
Supabase supports many OAuth providers:- Discord - Popular with anime communities
- Twitter - Social login
- Microsoft - Enterprise SSO
- Facebook - Social login
- Apple - iOS apps
Authentication in Your App
AniDojo provides authentication through theAuthContext and Supabase clients.
Using AuthContext (Client Components)
Sign Up with Email
Sign In with Email
Sign In with OAuth
Sign Out
Get Current User (Server-Side)
Automatic Profile Creation
When a user signs up, a profile is automatically created via database trigger:- Fires when a new user is created in
auth.users - Extracts username from metadata or uses email prefix
- Creates a matching profile in
public.profiles
Session Management
Supabase handles session management automatically:- Session tokens stored in cookies
- Automatic refresh before expiration
- Secure httpOnly cookies (server-side)
- PKCE flow for OAuth
Session Configuration
Configure session settings in Authentication → Settings:- JWT expiry: 3600 seconds (1 hour) default
- Refresh token rotation: Enabled for security
- Session timeout: Configure inactivity timeout
Password Reset Flow
Protected Routes
Protect routes that require authentication:middleware.ts
Testing Authentication
Test email signup
- Navigate to
/signupin your app - Create a new account
- Check your email for confirmation link
- Verify profile was created in database
Test email signin
- Navigate to
/login - Sign in with your credentials
- Verify you’re redirected to dashboard
Test OAuth (if enabled)
- Click “Sign in with Google” button
- Complete OAuth flow
- Verify profile created
Troubleshooting
Email not received
- Check Supabase logs: Authentication → Logs
- Verify email provider is configured correctly
- Check spam folder
- For development, check Supabase Authentication → Users for confirmation link
OAuth redirect error
- Verify redirect URL in OAuth provider matches Supabase callback URL
- Check redirect URL is added in Authentication → URL Configuration
- Ensure OAuth app is approved/published (not in testing mode)
Profile not created
- Check database trigger exists:
on_auth_user_created - View trigger logs in Database → Logs
- Manually verify trigger function:
handle_new_user() - Check for errors in Supabase logs
Session expires immediately
- Check JWT expiry setting isn’t too short
- Verify cookies are being set (check browser dev tools)
- Ensure middleware is refreshing session correctly
Security Best Practices
Next Steps
API Integration
Connect to the Jikan anime API for anime data
Database Setup
Review the database schema and RLS policies