Prerequisites
Before you begin, ensure you have:- A WorkOS account (free for development)
- Access to the WorkOS Dashboard
- Hazel Chat source code cloned locally
Overview
WorkOS AuthKit provides enterprise-ready authentication with:- Multi-provider auth - Email/password, Google, GitHub, Microsoft, and more
- Enterprise SSO - SAML and OIDC support
- Organization management - Multi-tenant with role-based access
- Session management - Secure JWT tokens
- MFA support - Two-factor authentication
Step-by-Step Setup
1. Create a WorkOS Account
Sign up for WorkOS
Go to workos.com and create a free account.
WorkOS offers a free tier for development with unlimited users.
Access your dashboard
Navigate to dashboard.workos.com to configure your application.
2. Enable AuthKit
AuthKit is WorkOS’s managed authentication solution.Configure your app
Set your application name and branding:
- App Name: Hazel Chat (or your preferred name)
- Logo: Optional - upload your logo
- Primary Color: Optional - customize the auth UI
You can enable additional sign-in methods later. Email + Password is sufficient to get started.
3. Configure Redirect URIs
Redirect URIs tell WorkOS where to send users after authentication.Add production redirect URI (when ready)
When deploying to production, add your production callback URL:Replace
api.example.com with your actual backend domain.4. Create Required Roles
Hazel Chat uses custom roles for organization access control.Create Owner role
Click “Create Role” and configure:
- Role Slug:
owner - Name: Owner
- Description: Full access, can delete organization
Create Admin role
Create another role:
- Role Slug:
admin - Name: Admin
- Description: Can manage members and settings
These role slugs (
owner, admin, member) are hardcoded in Hazel Chat. They must match exactly.Role Permissions Matrix
| Role | Delete Org | Manage Members | Manage Settings | Channel Access |
|---|---|---|---|---|
| Owner | ✅ | ✅ | ✅ | ✅ |
| Admin | ❌ | ✅ | ✅ | ✅ |
| Member | ❌ | ❌ | ❌ | ✅ |
5. Get API Credentials
Retrieve your API credentials from the WorkOS dashboard.Get API Key
Go to API Keys in the dashboard.Copy your API Key:
- Development:
sk_test_... - Production:
sk_live_...
6. Configure Environment Variables
Add WorkOS credentials to your environment files.The frontend redirect URI is different from the backend. The frontend receives the code and exchanges it via the backend.
7. Test Authentication
Verify your WorkOS configuration is working.Open the application
Navigate to http://localhost:3000
Complete authentication
Sign up with email or OAuth provider.You should be redirected back to Hazel Chat after successful authentication.
Verify user creation
Check that the user was created in your database:Open http://localhost:4983 and check the
users table.Production Configuration
Update Redirect URIs
When deploying to production:Configure Custom Domain (Optional)
Customize the authentication URL:Webhooks (Optional)
Set up webhooks to receive events from WorkOS.Select events
Subscribe to relevant events:
user.createduser.updateduser.deletedorganization_membership.createdorganization_membership.deleted
Multi-Organization Setup
Creating Organizations
Users can belong to multiple organizations:Organization Switching
Users can switch between organizations:Troubleshooting
Redirect URI mismatch error
Redirect URI mismatch error
Error:
redirect_uri_mismatchSolution: Verify the redirect URI in your .env file matches exactly what’s configured in WorkOS dashboard:Invalid client ID error
Invalid client ID error
Error: Copy the correct value from WorkOS dashboard → Configuration.
invalid_clientSolution: Verify your WORKOS_CLIENT_ID is correct:API key authentication fails
API key authentication fails
Error: Never mix development and production keys.
Unauthorized or Invalid API keySolution: Check you’re using the correct API key for your environment:Role not found error
Role not found error
Error:
Role 'owner' not foundSolution: Create all three required roles in WorkOS dashboard → Roles:owneradminmember
User not syncing to database
User not syncing to database
Error: User authenticates but doesn’t appear in databaseSolution: Check backend logs for errors:Verify
DATABASE_URL is correct and database is accessible.Security Best Practices
API Keys
Use different keys per environment
Development and production must use separate API keys:
- Development:
sk_test_... - Production:
sk_live_...
Redirect URIs
Cookie Security
Advanced Configuration
Custom Email Templates
Customize authentication emails:- Go to WorkOS dashboard → Email Templates
- Edit templates for:
- Welcome emails
- Password reset
- Email verification
- Magic links
MFA Setup
Enable multi-factor authentication:- Go to Authentication → MFA
- Enable MFA options:
- SMS
- Authenticator apps (TOTP)
- WebAuthn
Session Duration
Configure session expiration:- Go to Authentication → Session Settings
- Set session duration (default: 7 days)
- Configure refresh token expiration
Next Steps
Authentication Guide
Learn about the authentication flow
Environment Variables
Complete configuration reference
Deployment
Deploy to production
Database Setup
Set up PostgreSQL