Overview
EpiNeko uses Supabase Auth for secure, scalable authentication. The system supports email/password authentication with a unique username-based login feature.All authentication operations are handled through Next.js Server Actions, providing a seamless developer experience without the need for separate API routes.
Authentication Architecture
EpiNeko implements a multi-layered authentication system:Supabase Client Setup
EpiNeko uses two different Supabase clients depending on the execution context:Browser Client
Used in client components for client-side operations:Server Client
Used in server components and server actions for server-side operations:Authentication Flows
User Signup
The signup flow creates a new user account and automatically generates a profile:User Login
EpiNeko supports login with both email and username:1
User enters identifier
The user provides either an email or username along with their password
2
Identifier validation
The system checks if the identifier contains ’@’ to determine if it’s an email
3
Username lookup
If it’s a username, the system queries the profiles table to find the associated email
4
Authentication
Supabase Auth validates the email and password combination
5
Session creation
On success, a session is created and cookies are set
User Logout
Simple logout functionality that clears the session:Session Management
Middleware
EpiNeko uses Next.js middleware to automatically refresh user sessions on every request:The middleware automatically refreshes the authentication token on every request, ensuring users stay logged in without manual intervention.
Profile Management
Automatic Profile Creation
Profiles are automatically created when a user signs up through a database trigger:supabase/migrations/20260218_initial_schema.sql
Row Level Security (RLS)
Profiles are protected with Row Level Security policies:Getting the Current User
Fetch the authenticated user in server components:Protecting Routes
Create protected routes by checking authentication status:app/protected/page.tsx
Customization
Adding Social Authentication
To add OAuth providers (Google, GitHub, etc.):- Enable the provider in Supabase Dashboard (Authentication > Providers)
- Add the OAuth redirect URL to your provider’s app settings
- Update your login page with social buttons:
Email Verification
Enable email verification in Supabase Dashboard (Authentication > Email Templates):Password Recovery
Implement password reset:Troubleshooting
Session not persisting
Session not persisting
Ensure middleware is properly configured and running on all routes. Check that cookies are being set correctly.
Username login not working
Username login not working
Verify that the username is stored in the profiles table and is properly indexed. Check that the email column is added to profiles.
Profile not created on signup
Profile not created on signup
Check that the database trigger is installed correctly. Verify that user metadata is being passed during signup.