Overview
The Nurse Handoff Helper requires nurse accounts to be created in both the database and Supabase Auth. This guide explains how to create and manage these accounts using the provided CLI scripts.The application includes automated scripts to simplify nurse account creation and management. These scripts handle both database records and authentication accounts.
Prerequisites
Before creating nurse accounts, ensure:- Supabase database is set up with the
nursestable - Environment variables are configured, especially
SUPABASE_SERVICE_KEY - You have the service role key (required for creating auth accounts)
Available Commands
The application provides npm scripts for managing nurse accounts:List Existing Nurses
To view all nurses in your database:- Nurse name
- Email address
- Database ID
- Authentication account status (linked or not linked)
Example Output
Create Authentication Accounts
To create Supabase Auth accounts for nurses in your database:scripts/setup-nurse-accounts.js:76):
- Fetches all nurses from the database
- Skips nurses who already have auth accounts
- Generates email addresses if missing (format:
[email protected]) - Creates Supabase Auth accounts with temporary passwords
- Links the auth account to the nurse record
- Displays temporary passwords for each new account
How It Works
Check Existing Accounts
For each nurse, it checks if they already have an
auth_user_id linked.
If yes, the nurse is skipped.Create Auth Account
Creates a Supabase Auth user with:
- Email address
- Temporary password (
Temp{nurse_id}{timestamp}) - Auto-confirmed email
- User metadata (name and nurse_id)
Example Output
Adding Nurses to Database
Before creating auth accounts, you need to add nurse records to the database. You can do this via:Option 1: Supabase Dashboard
- Go to your Supabase project
- Navigate to Table Editor → nurses
- Click Insert row
- Fill in:
- name: Full name (required)
- email: Email address (optional, will be auto-generated)
- Click Save
Option 2: SQL Insert
Option 3: API Endpoint
The application automatically creates nurse records during first login if they don’t exist (server/index.js:35).
Password Management
Temporary Passwords
When accounts are created, they receive temporary passwords in the format:Temp550e84001709123456
First Login Flow
- Nurse logs in with email and temporary password
- Application authenticates via Supabase Auth
- Nurse should be prompted to change password (implement this in your frontend)
Resetting Passwords
To reset nurse passwords:- Go to Authentication → Users
- Find the nurse’s auth account
- Click … → Reset password
- Send reset email or set new password manually
Account Linking
The script handles three scenarios:New Account
No auth account exists. Creates new Supabase Auth user and links it.
Existing Account
Auth account exists but not linked. Links existing auth user to nurse record.
Already Linked
Nurse already has auth_user_id. Skips creation.
API Endpoint for Account Creation
You can also create accounts programmatically via the API endpoint (server/index.js:580):
Request
Response
Troubleshooting
Error: SUPABASE_SERVICE_KEY is required
Error: SUPABASE_SERVICE_KEY is required
The service role key is required to create auth accounts. Add it to your Get it from Project Settings → API → service_role in Supabase dashboard.
.env file:Error: No nurses found in database
Error: No nurses found in database
You need to add nurses to the
nurses table first. Use one of the methods described in “Adding Nurses to Database” above.Error: Email already exists
Error: Email already exists
If you see “User with this email already exists”, the script will attempt to link the existing auth user to the nurse record instead of creating a new one.
Account created but failed to link
Account created but failed to link
This error indicates the auth account was created successfully but couldn’t be linked to the nurse record. You may need to manually update the
auth_user_id in the nurses table.Security Best Practices
Change Default Passwords
Ensure nurses change their temporary passwords on first login.
Use Strong Passwords
Implement password strength requirements in your authentication flow.
Secure Credential Sharing
Share temporary passwords through secure channels (not email or Slack).
Regular Audits
Periodically review nurse accounts and remove inactive users.
Next Steps
After creating nurse accounts:- Test login functionality with
npm run test:login - Start the application with
npm start - Have nurses log in and change their passwords
- Assign nurses to rooms and patients
