Overview
Nurse Handoff Helper uses Supabase Auth to provide secure, healthcare-grade authentication. The system links authenticated users to nurse profiles in the database, enabling role-based access and audit trails.Architecture
Authentication Flow
Initial Load
From~/workspace/source/src/App.jsx:14-65:
The app includes a 15-second timeout to prevent infinite loading states if auth initialization hangs.
Session Check
From~/workspace/source/src/App.jsx:67-92:
Auto-Create Nurse Records
If an authenticated user doesn’t have a nurse profile, one is created automatically at~/workspace/source/src/App.jsx:114-138:
Database Schema
Nurses Table
Auth Users Table (Supabase)
Managed by Supabase Auth, includes:id- UUID primary keyemail- User emailencrypted_password- Hashed passwordemail_confirmed_at- Email verification timestampuser_metadata- Custom data (name, etc.)last_sign_in_at- Session tracking
Admin Account Creation
Bulk Create Accounts
The backend provides an admin endpoint to create auth accounts for existing nurses at~/workspace/source/server/index.js:580-717:
Endpoint: POST /api/nurses/create-accounts
- Scans all nurses in the database
- Skips nurses with existing
auth_user_id - Links nurses to existing auth accounts by email
- Creates new auth accounts with temporary passwords
- Updates nurse records with
auth_user_id
~/workspace/source/server/index.js:658-683
Session Management
Persistent Sessions
Supabase automatically handles session persistence using:- localStorage - Stores refresh tokens
- Session tokens - Short-lived access tokens
- Auto-refresh - Refreshes tokens before expiry
Auth State Listener
From~/workspace/source/src/App.jsx:30-40:
SIGNED_IN- User logged inSIGNED_OUT- User logged outTOKEN_REFRESHED- Access token refreshedUSER_UPDATED- User profile updatedPASSWORD_RECOVERY- Password reset initiated
Logout
From~/workspace/source/src/App.jsx:163-167:
Configuration
Environment Variables
.env
Client Initialization
The Supabase client is initialized once and shared across the app:Backend Clients
From~/workspace/source/server/index.js:32-49:
The admin client is only initialized if
SUPABASE_SERVICE_KEY is provided. It’s used for privileged operations like creating user accounts.Security Features
Row Level Security
Database policies ensure nurses only access their assigned patients
Password Hashing
Supabase uses bcrypt for secure password storage
JWT Tokens
Short-lived access tokens with automatic refresh
Email Verification
Optional email confirmation for new accounts
User Interface
Loading State
From~/workspace/source/src/App.jsx:169-180:
Login View
From~/workspace/source/src/App.jsx:182-184:
Authenticated View
From~/workspace/source/src/App.jsx:186-204:
API Authentication
While the current implementation doesn’t require auth tokens for API calls, it’s recommended to add them:Health Check
Verify Supabase connection:~/workspace/source/server/index.js:52-60
Troubleshooting
Infinite Loading
Infinite Loading
Symptoms: App shows “Loading…” indefinitelyCauses:
- Supabase client not initialized
- Network issues
- Invalid environment variables
- Check
.envfile hasSUPABASE_URLandSUPABASE_ANON_KEY - Verify Supabase project is active
- Check browser console for errors
- Wait for 15-second timeout to trigger
Login Failed
Login Failed
Symptoms: Cannot log in with valid credentialsCauses:
- Email not confirmed
- User disabled
- Wrong environment
- Check Supabase Auth dashboard for user status
- Verify email is confirmed
- Reset password via forgot password flow
- Check for typos in email/password
Nurse Record Not Found
Nurse Record Not Found
Symptoms: User authenticates but nurse data missingCauses:
- Auth user not linked to nurse record
- Database query failed
- System creates nurse record automatically
- Check
nursestable in Supabase dashboard - Verify
auth_user_idis set correctly - Run
/api/nurses/create-accountsto link accounts
Service Key Required
Service Key Required
Symptoms: Admin endpoints return 503 errorCauses:
SUPABASE_SERVICE_KEYnot set
- Add service role key to
.envfile - Get key from Supabase dashboard → Settings → API
- Restart server after adding key
Best Practices
Password Policies
Password Policies
- Require minimum 8 characters
- Include uppercase, lowercase, numbers
- Force password change for temporary passwords
- Implement password reset flow
Session Security
Session Security
- Set appropriate token expiry times
- Implement auto-logout on inactivity
- Clear sensitive data on logout
- Use secure, httpOnly cookies in production
Account Management
Account Management
- Implement email verification
- Add multi-factor authentication
- Log authentication events
- Monitor failed login attempts
Data Protection
Data Protection
- Enable Row Level Security (RLS)
- Restrict API access to authenticated users
- Audit access to patient records
- Implement role-based permissions
Next Steps
Patient Handoff
Learn about handoff note generation
Supabase Setup
Explore the complete database structure and setup
