Google OAuth Flow
DelightBridge authenticates users through Google OAuth using NextAuth.js. The authentication configuration is split across two files:auth.config.ts- Base authorization callbacksauth.ts- Google provider setup and user provisioning
Sign In Process
User clicks Sign In
Users are redirected to Google’s OAuth consent screen to authorize the application.
Authorization Check
After Google authentication, DelightBridge checks if the user is authorized:Users must either be in the
ADMIN_EMAILS list or exist in the workspace_members table.Permission Assignment
The system assigns permissions based on admin status:Admin users always receive
admin permission, regardless of database settings.Admin Email Configuration
Admin access is controlled through theADMIN_EMAILS environment variable and a default admin list.
Setting Admin Emails
Add admin emails to your.env.local file:
Emails in
ADMIN_EMAILS are automatically normalized (trimmed and lowercased) before comparison.How Admin Emails Work
ThegetAdminEmails() function from admin-emails.ts:3 merges environment-configured emails with default admins:
admin-emails.ts:1:
Session Management
DelightBridge maintains user sessions through NextAuth with additional permission enforcement.Session Callback
The session callback inauth.ts:62 runs on every request to verify and update user permissions:
This callback automatically upgrades users to admin if their email is added to
ADMIN_EMAILS after their initial login.Requiring Authentication in API Routes
API routes use helper functions fromsession.ts to enforce authentication:
Workspace Members
Non-admin users must be added to theworkspace_members table to access DelightBridge.
Adding Members
Admins can add workspace members through the Settings modal or via the API:Member Login Flow
- User authenticates with Google OAuth
- System checks
workspace_memberstable for their email - If found, user is granted access with their assigned permission level
- If not found and not in
ADMIN_EMAILS, login is rejected withunauthorizederror
Example: Adding a member with edit permission
Example: Adding a member with edit permission
Protected Routes
Theauthorized callback in auth.config.ts:8 protects all routes except /login:
/login.
Environment Variables
Required for Google OAuth:Troubleshooting
User Cannot Log In
Error: unauthorized
Error: unauthorized
User sees blank screen after login
User sees blank screen after login
Check browser console for errors. Ensure
GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are correctly set.Admin user has wrong permissions
Admin user has wrong permissions
The session callback auto-corrects this on next request. Have the user refresh the page or log out and back in.
Permission Issues
Admin added to ADMIN_EMAILS but still has limited access
Admin added to ADMIN_EMAILS but still has limited access
The session callback updates permissions on the next request. Ask the user to refresh the page.
Cannot add workspace member with admin permission
Cannot add workspace member with admin permission
Only emails in
ADMIN_EMAILS can have admin permission. Add the email to your environment variable instead.