Authentication is handled by Supabase Auth with:
- Email/password authentication
- Email verification via SMTP
- Password reset
- Session management
VITE_EMAIL_PROVIDER=sendgrid
VITE_SENDGRID_API_KEY=SG.your-api-key
VITE_EMAIL_PROVIDER=mandrill
VITE_MANDRILL_API_KEY=md-your-api-key
-
Enable Auth Service
- Go to Supabase Dashboard
- Select your project
- Navigate to Authentication > Settings
- Enable Email auth provider
-
Configure SMTP
select setup_smtp_auth( 'sendgrid', -- or 'mandrill' 'your-api-key', '[email protected]', 'ClappCode' );
-
Configure Email Templates
- Go to Authentication > Email Templates
- Customize:
- Confirmation Email
- Reset Password Email
- Magic Link Email
- Change Email Address
-
Set Environment Variables
VITE_SUPABASE_URL=your-project-url
VITE_SUPABASE_ANON_KEY=your-anon-key
await auth.signUp(email, password);
await auth.signIn(email, password);
await auth.resetPassword(email);
await auth.signOut();
Use AuthGuard component:
<Route
path="/dashboard"
element={
<AuthGuard>
<Dashboard />
</AuthGuard>
}
/>
-
User Registration
- User submits signup form
- Account created (unconfirmed)
- Verification email sent
-
Email Verification
- User clicks verification link
- Token validated
- Account confirmed
- Redirect to login
-
Password Reset
- User requests reset
- Reset email sent
- User sets new password
- Session updated
Sessions are automatically handled by Supabase Auth:
- JWT tokens
- Refresh tokens
- Auto refresh
- Secure storage
Auth errors are logged and displayed to users via toast notifications:
try {
await auth.signUp(email, password);
} catch (error) {
toast.error('Failed to create account');
logger.error('Signup error:', error);
}
-
Password Requirements
- Minimum 8 characters
- Mix of letters/numbers
- Special characters
-
Rate Limiting
- Login attempts
- Password resets
- Email verification
-
Session Security
- Short token expiry
- Secure cookie storage
- HTTPS only
test('signup validation', () => {
expect(validateSignup(validData)).toBe(true);
expect(validateSignup(invalidData)).toBe(false);
});
test('auth flow', async () => {
await signUp(testUser);
await verifyEmail(token);
await signIn(testUser);
expect(isAuthenticated()).toBe(true);
});
-
Email Not Received
- Check spam folder
- Verify email address
- Check SMTP settings
-
Invalid Token
- Token expired
- Already used
- Malformed URL
-
Session Issues
- Clear local storage
- Check token expiry
- Verify credentials