Overview
User management actions handle user accounts, team invitations, role assignments, and profile updates. All operations are scoped to the admin’s team for multi-tenant isolation. Actions are located in:src/app/actions/admin.ts- Admin operationssrc/app/actions/user.ts- Profile operationssrc/app/actions/auth.ts- Registration
getUsers
Retrieve all users and pending invitations for the admin’s team.Operation status
Combined array of users and pending invitations, sorted by creation date:User Objects:
id: User IDname: Display nameemail: Email addressrole: User rolestatus: Account status (“ACTIVE” | “PENDING” | “SUSPENDED”)image: Profile image URLcreatedAt: Registration date_count.vulnerabilities: Number of vulnerabilities createdisInvitation:false
id: Invitation IDname: “Pending User”email: Invited emailrole: Assigned rolestatus: “PENDING”image:nullcreatedAt: Invitation date_count.vulnerabilities:0isInvitation:true
createUser
Create a new user directly (without invitation flow).User’s display name
User’s email address (must be unique)
Initial password (will be hashed with bcrypt, cost factor 12)
User’s role within the team
Account status
- User is automatically assigned to the admin’s team
isOnboardedis set totrue(skips onboarding flow)createdByIdis set to the admin’s user ID- Duplicate email returns error
The created user object
- “Admin must belong to a team to create users.”
- “A user with this email already exists”
- “You must be an admin to create users”
createInvitation
Invite a user to join the team via email.Email address to invite
Role to assign when user registers
- Checks if email is already registered (returns error if exists)
- Deletes any existing invitation for this email (allows re-inviting)
- Generates a secure UUID token
- Creates invitation with 24-hour expiration
- Sends invitation email via Resend
- Creates audit log entry
- Subject: “You’ve been invited to VulnTrack”
- Includes invitation link:
{APP_URL}/register?token={token} - Plain text fallback included
Whether invitation was created
“Invitation sent successfully”
The generated invitation token (UUID)
Relative path to registration:
/register?token={token}deleteInvitation
Revoke a pending invitation.ID of the invitation to revoke
- Verifies admin and invitation belong to the same team
- Returns “Unauthorized access to invitation” for cross-team attempts
DELETE_INVITATION with email address
updateUser
Update user account details.ID of user to update
Updated display name
Updated role
Updated account status
- Admin and target user must be in the same team
- Returns “Unauthorized access to user” for cross-team attempts
Email updates are intentionally disabled due to authentication implications. To change a user’s email, they must register a new account.
updateUserRole
Update only a user’s role (specialized operation).ID of user to update
New role
- Updates user’s role immediately
- User’s JWT is refreshed on next request (no re-login needed)
- Role change takes effect across all active sessions
deleteUser
Delete a user account.ID of user to delete
- Admin and target user must be in the same team
- Cannot delete users from other teams
updateProfile
Update the current user’s profile (non-admin operation).Updated display name
Profile image URL
- Updates user’s name and profile image
- Sets
isOnboarded: true(completes onboarding) - Revalidates
/dashboardand/dashboard/settings
- Onboarding flow completion
- Profile settings page
- Avatar updates
Invitation Flow
Complete invitation-based registration flow:1. Admin Creates Invitation
2. User Receives Email
Email contains link to registration page with token:3. User Registers
4. System Processing
- Validates token (checks expiration, email match)
- Creates user with role from invitation
- Assigns user to inviter’s team
- Deletes invitation record
- Sets
createdByIdto inviter’s ID
5. User Can Login
User is now a team member with assigned role.Rate Limiting
User creation and invitation actions inherit rate limiting from the registration endpoint:- Limit: 5 attempts per minute per IP
- Window: 60 seconds
Audit Trail
All user management operations are logged:| Action | Event Type | Details |
|---|---|---|
| Create User | CREATE_USER | ”User created by [email protected]” |
| Update User | UPDATE_USER | ”User updated by [email protected]” |
| Update Role | UPDATE_ROLE | ”Role updated to ADMIN” |
| Delete User | DELETE_USER | ”User deleted” |
| Create Invitation | CREATE_INVITATION | ”Invited [email protected] as CONTRIBUTOR” |
| Delete Invitation | DELETE_INVITATION | ”Invitation revoked for [email protected]” |
Example: User Management Dashboard
Next Steps
Authentication
Learn about session management
Teams
Understand team isolation and structure