.agents/features/authentication.md
The authentication feature handles user identity creation, sign-in, and JWT session management across all editions. It supports email/password credentials, federated OAuth providers (Google, SAML), and invitation-only sign-up when a platform is configured. On first sign-up (no platformId), a new platform and personal project are created automatically. The token is a short-lived JWT (7 days) signed with a shared secret, and sessions are invalidated by rotating the tokenVersion on the UserIdentity record.
packages/server/api/src/app/authentication/authentication.controller.ts — Fastify routes: POST /sign-up, POST /sign-in, POST /switch-platformpackages/server/api/src/app/authentication/authentication.service.ts — core service: signUp, signInWithPassword, federatedAuthn, switchPlatformpackages/server/api/src/app/authentication/authentication-utils.ts — shared guards (domain check, email auth check, invitation check) and getProjectAndToken helperpackages/server/api/src/app/authentication/lib/access-token-manager.ts — JWT generation (generateToken, generateEngineToken, generateWorkerToken) and verifyPrincipalpackages/server/api/src/app/authentication/lib/password-hasher.ts — bcrypt helperspackages/server/api/src/app/authentication/user-identity/user-identity-entity.ts — user_identity table entitypackages/server/api/src/app/authentication/user-identity/user-identity-service.ts — identity CRUD, password verification, verify(), getIdentityByEmail()packages/shared/src/lib/core/authentication/dto/authentication-response.ts — AuthenticationResponse Zod schemapackages/web/src/features/authentication/hooks/auth-hooks.ts — React Query mutations: useSignIn, useSignUp, useSendOtpEmail, useResetPassword, useVerifyEmailpackages/web/src/features/authentication/components/sign-in-form.tsx — sign-in form componentpackages/web/src/features/authentication/components/sign-up-form.tsx — sign-up form componentpackages/web/src/features/authentication/components/third-party-logins.tsx — OAuth provider buttonspackages/web/src/app/routes/auth-routes.tsx — route declarations: /sign-in, /sign-up, /forget-password, /reset-password, /verify-email, /invitationAll editions (Community, Enterprise, Cloud). Email auth checks and domain-allow-listing guards are skipped on Community edition. OTP email verification is sent on Cloud; on Community and Enterprise the identity is automatically marked verified.
UserIdentity; rotating it invalidates all existing JWTsUSER, ENGINE, WORKER, SERVICE, UNKNOWNuser_identity (UserIdentityEntity)| Column | Type | Notes |
|---|---|---|
| id | string | ApId |
| string | unique | |
| password | string | bcrypt hash |
| firstName | string | |
| lastName | string | |
| verified | boolean | false until OTP confirmed or auto-verified |
| provider | string | UserIdentityProvider enum value |
| tokenVersion | string (nullable) | rotated on password change / logout-all |
| trackEvents | boolean (nullable) | |
| newsLetter | boolean (nullable) | |
| imageUrl | string (nullable) | OAuth avatar URL |
| Method | Path | Security | Description |
|---|---|---|---|
| POST | /v1/authentication/sign-up | public | Create identity + user + platform (or join existing platform via invitation) |
| POST | /v1/authentication/sign-in | public | Verify password, return JWT |
| POST | /v1/authentication/switch-platform | publicPlatform (USER) | Exchange current token for a token on a different platform |
All endpoints are rate-limited via API_RATE_LIMIT_AUTHN_MAX / API_RATE_LIMIT_AUTHN_WINDOW system props.
authenticationServicesignUp(params) — validates domain and invitation (when platformId is set), creates identity and user, on new platform creates a personal project and sends OTP or auto-verifiessignInWithPassword(params) — verifies bcrypt hash, checks domain and email-auth settings, returns AuthenticationResponsefederatedAuthn(params) — used by OAuth/SAML callbacks; creates or retrieves identity and user, then returns tokenswitchPlatform(params) — finds an existing user record on the target platform and issues a new tokenaccessTokenManagergenerateToken(principal, expiresInSeconds?) — signs a Principal as JWT; default 7 daysgenerateEngineToken({ jobId, projectId, platformId }) — long-lived token for flow enginegenerateWorkerToken() — long-lived token for worker processesverifyPrincipal(token) — decodes JWT, checks tokenVersion match and user active statusUserIdentity createdUser created with PlatformRole.ADMINPlatform created (named "<firstName>'s Platform")Project created with ProjectType.PERSONALotpServiceApFlagId.USER_CREATED flag savedSIGNED_UP event fired