Users

Internal system users who log in and interact with Renewa One. Every user is backed by a contact record for personal information. Users authenticate via Authentication and are authorized via RBAC Authorization.

Source Files

LayerPath
Schemabackend/src/db/schema.ts (line ~496)
Routesbackend/src/routes/users.ts
Auth Servicebackend/src/services/auth-service.ts
Profile Pagefrontend/src/pages/Profile.tsx
Profile Sectionsfrontend/src/pages/ProfilePersonalInfoSection.tsx, ProfilePasswordSection.tsx, ProfileTwoFactorSection.tsx, ProfileResponsibilitySection.tsx, ProfileDeleteAccountSection.tsx
Adminfrontend/src/pages/admin/UsersAdmin.tsx
Auth Storefrontend/src/store/auth.ts (Zustand)

Database Tables

TablePurpose
usersMain entity — email, type, role, auth fields, contact link
sessionsJWT session tokens with rotation and expiry
user_skillsM2M linking users to skills with levels
user_departmentsM2M linking users to Departments (with isPrimary flag)

Key Fields

FieldTypeNotes
emailvarchar(255)Login email (unique, required)
passwordHashtextArgon2id hash via Bun.password.hash()
userTypeenuminternal or external
internalRoleenumadmin or employee (only for internal users)
contactIduuid FKMandatory link to Contacts for personal info
avatarUrlvarcharProfile picture URL
languagevarchar(2)UI language preference (de/en)
isActivebooleanAccount active flag
entraIdvarcharMicrosoft Entra ID for SSO
authProviderenumlocal or Entra ID
twoFactorSecrettextTOTP secret (encrypted)
twoFactorEnabledbooleanWhether 2FA is active

User Types

TypeInternal RoleDescription
internaladminFull system access, user management
internalemployeeStandard internal user
externalCraftsmen, partners, external collaborators

Relationships

User *──1 Contact (personal info source of truth)
User *──* Departments (via user_departments)
User *──* Skills (via user_skills)
User 1──* Sessions
User 1──* Buildings (creator)
User 1──* Projects (creator)

Authentication Flow

  1. Login with email/password (argon2id verification via Bun.password)
  2. Optional 2FA via TOTP (twoFactorSecret + authenticator app)
  3. JWT access token + refresh token stored in sessions table
  4. Session rotation with previous-token grace period
  5. SSO option via Microsoft Entra ID (authProvider: 'entra')

See Authentication for full details.

Frontend State

  • Zustand store at frontend/src/store/auth.ts manages current user, token, and auth state
  • Profile page with five sections: personal info, password, 2FA, responsibility areas, account deletion
  • Admin panel at UsersAdmin.tsx for user management (restricted to admins and team leads)

Features

  • Hybrid RBAC — user type + internal role + per-resource roles (RBAC Authorization)
  • 2FA support — TOTP-based two-factor authentication
  • Department membership — users belong to Departments with primary department flag
  • Skill tracking — user competencies via skills and levels
  • Session management — JWT with refresh rotation and grace periods

Authentication | RBAC Authorization | Contacts | Departments | Admin Dashboard | Database Architecture | Service Layer Pattern