From 7cc3cdab05222fc662e45489e42a79e9a89d0263 Mon Sep 17 00:00:00 2001 From: Abhishek Chatterjee Date: Thu, 26 Nov 2026 23:27:35 +0530 Subject: [PATCH 1/2] feat(ross): #243: make isVerifiedField mandatory and rename usernameField to emailField --- ross/e2e/auth.spec.ts | 25 ++- ross/e2e/custom-endpoints.spec.ts | 9 +- ross/e2e/delete-ssp.spec.ts | 12 +- ross/e2e/rbac.spec.ts | 24 ++- ross/e2e/variant-override.spec.ts | 17 +- ross/src/interfaces/config.ts | 4 +- ross/src/lib/auth/up-auth.ts | 10 +- ross/src/lib/config/route-registry.ts | 17 +- ross/src/routes/auth/change-email.ts | 32 ++-- ross/src/routes/auth/edit-me.ts | 18 +-- ross/src/routes/auth/forgot-password.ts | 29 ++-- ross/src/routes/auth/login.ts | 27 ++-- ross/src/routes/auth/otp-verify.ts | 52 +++---- ross/src/routes/auth/refresh.ts | 2 +- ross/src/routes/auth/registration.ts | 92 +++-------- ross/src/routes/auth/resend-otp.ts | 29 ++-- ross/src/server.ts | 12 +- ross/src/validators/config/schema.ts | 4 +- ross/src/validators/config/validate-auth.ts | 58 ++++--- .../config/__goldens__/full.resolved.json | 2 +- ross/tests/fixtures/config/full.json | 2 +- ross/tests/helpers/auth-config.ts | 6 +- ross/tests/lib/auth/up-auth.test.ts | 12 +- ross/tests/lib/config/api.test.ts | 3 +- ross/tests/lib/config/redact.test.ts | 3 +- ross/tests/lib/config/resolve.test.ts | 8 +- ross/tests/lib/config/route-registry.test.ts | 7 +- ross/tests/lib/schema/response.test.ts | 6 +- ross/tests/lib/server/prevalidation.test.ts | 6 +- ross/tests/migrator/index.test.ts | 3 +- ross/tests/plugin/auth.test.ts | 6 +- ross/tests/plugin/swagger.test.ts | 3 +- ross/tests/routes/aggregate.test.ts | 3 +- ross/tests/routes/auth-guards.test.ts | 3 +- ross/tests/routes/auth-providers.test.ts | 8 +- ross/tests/routes/auth-sso.test.ts | 8 +- ross/tests/routes/change-email.test.ts | 69 +-------- ross/tests/routes/change-password.test.ts | 3 +- .../routes/custom-endpoints-function.test.ts | 3 +- ross/tests/routes/custom-endpoints.test.ts | 3 +- ross/tests/routes/delete-me.test.ts | 3 +- ross/tests/routes/delete.test.ts | 6 +- ross/tests/routes/edit-me.test.ts | 3 +- ross/tests/routes/edit.test.ts | 3 +- ross/tests/routes/forgot-password.test.ts | 3 +- ross/tests/routes/get-all.test.ts | 3 +- ross/tests/routes/health.test.ts | 3 +- ross/tests/routes/index-route.test.ts | 3 +- ross/tests/routes/login.test.ts | 103 ++++++++----- ross/tests/routes/me.test.ts | 3 +- ross/tests/routes/otp-verify.test.ts | 64 +------- ross/tests/routes/post.test.ts | 3 +- ross/tests/routes/rbac-enforcement.test.ts | 3 +- ross/tests/routes/refresh.test.ts | 6 +- ross/tests/routes/registration.test.ts | 51 ++++-- ross/tests/routes/resend-otp.test.ts | 3 +- ross/tests/routes/search.test.ts | 3 +- ross/tests/server.test.ts | 43 ++++-- ross/tests/validators/config.test.ts | 145 ++++++++++++++++-- .../validators/config/validate-rbac.test.ts | 9 +- 60 files changed, 598 insertions(+), 505 deletions(-) diff --git a/ross/e2e/auth.spec.ts b/ross/e2e/auth.spec.ts index e7f47f55..f49bcc4a 100644 --- a/ross/e2e/auth.spec.ts +++ b/ross/e2e/auth.spec.ts @@ -321,6 +321,11 @@ const upAuthE2EConfig: AppConfigInput = { }, }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: 'e2e-up-auth-jwt-secret-at-least-32-chars-long!', @@ -335,8 +340,9 @@ const upAuthE2EConfig: AppConfigInput = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -369,6 +375,11 @@ const upAuthE2EConfig: AppConfigInput = { type: 'string', nullable: true, }, + is_active: { + type: 'boolean', + nullable: false, + default: false, + }, full_name: { type: 'string', nullable: true, @@ -470,7 +481,7 @@ test.describe expect(res.status()).toBe(400); }); - test('Successfully registers a new user without exposing secret password (HTTP 201)', async () => { + test('Successfully registers a new user and returns OTP challenge (HTTP 201)', async () => { const res = await server.request.post('/api/v1/auth/register', { data: testUser, }); @@ -478,10 +489,14 @@ test.describe const body = await res.json(); expect(body.code).toBe(201); expect(body.data).toBeDefined(); - expect(body.data.email).toBe(testUser.email); - expect(body.data.full_name).toBe(testUser.full_name); - expect(body.data.provider).toBe('up-auth'); + expect(body.data.requiresMfa).toBe(true); + expect(typeof body.data.ulid).toBe('string'); expect(body.data.password).toBeUndefined(); + + await server.app.db.query( + 'UPDATE users SET is_active = 1 WHERE email = ?;', + [testUser.email], + ); }); test('Rejects registration with duplicate email address (conflict)', async () => { diff --git a/ross/e2e/custom-endpoints.spec.ts b/ross/e2e/custom-endpoints.spec.ts index e21f4143..7805736b 100644 --- a/ross/e2e/custom-endpoints.spec.ts +++ b/ross/e2e/custom-endpoints.spec.ts @@ -46,6 +46,11 @@ const customEndpointsE2EConfig: AppConfigInput = { engine: 'memory', }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: 'e2e-custom-endpoints-super-secret-jwt-key-min-32-chars!', @@ -59,8 +64,9 @@ const customEndpointsE2EConfig: AppConfigInput = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -99,6 +105,7 @@ const customEndpointsE2EConfig: AppConfigInput = { password: {type: 'string', nullable: false, secret: true}, role: {type: 'string', nullable: false, default: 'viewer'}, provider: {type: 'string', nullable: true}, + is_active: {type: 'boolean', default: true}, }, }, projects: { diff --git a/ross/e2e/delete-ssp.spec.ts b/ross/e2e/delete-ssp.spec.ts index cecd3269..c0e78383 100644 --- a/ross/e2e/delete-ssp.spec.ts +++ b/ross/e2e/delete-ssp.spec.ts @@ -17,6 +17,11 @@ const deleteSspE2EConfig: AppConfigInput = { }, }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: 'super-secret-jwt-key-for-delete-ssp-testing-32chars', @@ -30,8 +35,9 @@ const deleteSspE2EConfig: AppConfigInput = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -61,6 +67,10 @@ const deleteSspE2EConfig: AppConfigInput = { type: 'string', nullable: true, }, + is_active: { + type: 'boolean', + default: true, + }, }, }, todos: { diff --git a/ross/e2e/rbac.spec.ts b/ross/e2e/rbac.spec.ts index 1880d237..7d73603d 100644 --- a/ross/e2e/rbac.spec.ts +++ b/ross/e2e/rbac.spec.ts @@ -19,6 +19,11 @@ const rbacE2EConfig: AppConfigInput = { }, }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: 'e2e-rbac-super-secret-jwt-key-for-testing-at-least-32-chars!', @@ -32,8 +37,9 @@ const rbacE2EConfig: AppConfigInput = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -94,6 +100,10 @@ const rbacE2EConfig: AppConfigInput = { type: 'string', nullable: true, }, + is_active: { + type: 'boolean', + default: true, + }, }, }, articles: { @@ -873,6 +883,11 @@ test.describe }, }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: @@ -887,8 +902,9 @@ test.describe type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -921,6 +937,10 @@ test.describe type: 'string', nullable: true, }, + is_active: { + type: 'boolean', + default: true, + }, }, }, }, diff --git a/ross/e2e/variant-override.spec.ts b/ross/e2e/variant-override.spec.ts index 0d601ba1..edbebf00 100644 --- a/ross/e2e/variant-override.spec.ts +++ b/ross/e2e/variant-override.spec.ts @@ -229,10 +229,19 @@ test.describe('Overridden Variant: Custom Endpoints & Authentication', () => { type: 'string', nullable: true, }, + is_active: { + type: 'boolean', + default: false, + }, }, }, }, }, + integrations: { + email: { + provider: 'dummy', + }, + }, authentication: { enabled: true, jwtSecret: 'e2e-variant-override-secret-key-at-least-32-chars-long!', @@ -246,8 +255,9 @@ test.describe('Overridden Variant: Custom Endpoints & Authentication', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -266,6 +276,11 @@ test.describe('Overridden Variant: Custom Endpoints & Authentication', () => { }); expect(regRes.status()).toBe(201); + await server.app.db.query( + 'UPDATE users SET is_active = 1 WHERE email = ?;', + ['variant-user@example.com'], + ); + // 2. Log in via POST /api/v2/auth/login const loginRes = await server.request.post('/api/v2/auth/login', { data: { diff --git a/ross/src/interfaces/config.ts b/ross/src/interfaces/config.ts index da0eb0fc..c8441d31 100644 --- a/ross/src/interfaces/config.ts +++ b/ross/src/interfaces/config.ts @@ -301,9 +301,9 @@ export interface AuthUserModelConfig { } export interface UpAuthFieldsConfig { - usernameField: string; + emailField: string; passwordField: string; - isVerifiedField?: string; + isVerifiedField: string; } export interface UpAuthConfigInput { diff --git a/ross/src/lib/auth/up-auth.ts b/ross/src/lib/auth/up-auth.ts index c7bcc4de..828d517f 100644 --- a/ross/src/lib/auth/up-auth.ts +++ b/ross/src/lib/auth/up-auth.ts @@ -10,9 +10,9 @@ export interface UpAuthRuntime { model: string; idField: string; providerField: string; - usernameField: string; + emailField: string; passwordField: string; - isVerifiedField?: string; + isVerifiedField: string; mfaRequired: boolean; } @@ -44,11 +44,9 @@ export function getUpAuth(config: ResolvedAppConfig): UpAuthRuntime | null { model: modelName, idField, providerField, - usernameField: fields.usernameField, + emailField: fields.emailField, passwordField: fields.passwordField, - ...(fields.isVerifiedField - ? {isVerifiedField: fields.isVerifiedField} - : {}), + isVerifiedField: fields.isVerifiedField, mfaRequired: provider.config.mfaRequired, }; } diff --git a/ross/src/lib/config/route-registry.ts b/ross/src/lib/config/route-registry.ts index 8e43fd58..610303af 100644 --- a/ross/src/lib/config/route-registry.ts +++ b/ross/src/lib/config/route-registry.ts @@ -104,7 +104,14 @@ export function getGeneratedApiIdentifiers( if (authModel && upAuth) { const upConfig = upAuth.config as UpAuthConfigInput; - const operations = ['registration', 'login', 'changePassword']; + const operations = [ + 'registration', + 'login', + 'changePassword', + 'otpVerifyRegister', + 'resendOtpRegister', + 'emailChange', + ]; if (config.integrations?.email) { operations.push( @@ -118,14 +125,6 @@ export function getGeneratedApiIdentifiers( operations.push('otpVerifyLogin', 'resendOtpLogin'); } - if (upConfig.fields?.isVerifiedField) { - operations.push( - 'otpVerifyRegister', - 'resendOtpRegister', - 'emailChange', - ); - } - for (const operation of operations) { addTargets('auth', authModel, 'unknown', operation); } diff --git a/ross/src/routes/auth/change-email.ts b/ross/src/routes/auth/change-email.ts index 7dfa5091..1cc5fb02 100644 --- a/ross/src/routes/auth/change-email.ts +++ b/ross/src/routes/auth/change-email.ts @@ -23,7 +23,7 @@ export function registerEmailChangeRoute( return; } - const {model, idField, usernameField, isVerifiedField} = upAuth; + const {model, idField, emailField, isVerifiedField} = upAuth; const authModelConfig = models[model]; @@ -44,7 +44,7 @@ export function registerEmailChangeRoute( model, authModelConfig, idField, - usernameField, + emailField, isVerifiedField, variant, identifier, @@ -59,14 +59,14 @@ function registerEmailChangeEndpoint( model: string, authModelConfig: ModelConfig, idField: string, - usernameField: string, - isVerifiedField: string | undefined, + emailField: string, + isVerifiedField: string, variant: string, apiIdentifier: string, policy: ResolvedApiPolicy, ): void { const schema: Record = generateSchema( - usernameField, + emailField, model, policy, ); @@ -93,13 +93,13 @@ function registerEmailChangeEndpoint( } const body = request.body as Record; - const newEmail = body[usernameField]; + const newEmail = body[emailField]; /* c8 ignore start */ if (!newEmail) { return reply .status(400) - .send(app.buildResponse(400, `${usernameField} is required`, null)); + .send(app.buildResponse(400, `${emailField} is required`, null)); } /* c8 ignore stop */ @@ -123,13 +123,11 @@ function registerEmailChangeEndpoint( app.buildResponse, ); - const setClauses = [`"${usernameField}" = $1`]; - const values: unknown[] = [newEmail]; - - if (isVerifiedField) { - setClauses.push(`"${isVerifiedField}" = $2`); - values.push(false); - } + const setClauses = [ + `"${emailField}" = $1`, + `"${isVerifiedField}" = $2`, + ]; + const values: unknown[] = [newEmail, false]; const updatedAtClause = buildUpdatedAtClause( authModelConfig, @@ -165,15 +163,15 @@ function registerEmailChangeEndpoint( } function generateSchema( - usernameField: string, + emailField: string, model: string, policy: ResolvedApiPolicy, ) { const bodySchema = { type: 'object', - required: [usernameField], + required: [emailField], properties: { - [usernameField]: {type: 'string', description: 'The new email address'}, + [emailField]: {type: 'string', description: 'The new email address'}, }, additionalProperties: false, }; diff --git a/ross/src/routes/auth/edit-me.ts b/ross/src/routes/auth/edit-me.ts index 31e7d29c..d15fcf59 100644 --- a/ross/src/routes/auth/edit-me.ts +++ b/ross/src/routes/auth/edit-me.ts @@ -26,7 +26,7 @@ export function registerEditMeRoute( const upAuth = getUpAuth(config); const {modelName: model, idField} = userModel; - const usernameField = upAuth?.usernameField ?? ''; + const emailField = upAuth?.emailField ?? ''; const passwordField = upAuth?.passwordField ?? ''; const isVerifiedField = upAuth?.isVerifiedField; @@ -49,7 +49,7 @@ export function registerEditMeRoute( model, authModelConfig, idField, - usernameField, + emailField, passwordField, isVerifiedField, variant, @@ -65,7 +65,7 @@ function registerEditMeEndpoint( model: string, authModelConfig: ModelConfig, idField: string, - usernameField: string, + emailField: string, passwordField: string, isVerifiedField: string | undefined, variant: string, @@ -76,7 +76,7 @@ function registerEditMeEndpoint( authModelConfig, model, idField, - usernameField, + emailField, passwordField, isVerifiedField, policy, @@ -106,9 +106,7 @@ function registerEditMeEndpoint( const body = request.body as ModelBody; const protectedFields = new Set( - [idField, usernameField, passwordField, isVerifiedField].filter( - Boolean, - ), + [idField, emailField, passwordField, isVerifiedField].filter(Boolean), ); const editableKeys = Object.keys(body).filter( k => !protectedFields.has(k) && !isManagedTimestampField(k), @@ -186,13 +184,13 @@ function generateSchema( authModelConfig: ModelConfig, model: string, idField: string, - usernameField: string, + emailField: string, passwordField: string, isVerifiedField: string | undefined, policy: ResolvedApiPolicy, ) { const protectedFields = new Set( - [idField, usernameField, passwordField, isVerifiedField].filter(Boolean), + [idField, emailField, passwordField, isVerifiedField].filter(Boolean), ); const bodyProperties: Record = {}; @@ -221,7 +219,7 @@ function generateSchema( const schema: Record = { summary: `Edit authenticated user profile for ${capitalizeFirstLetter(model)}`, - description: `Updates the profile of the currently authenticated user in the "${model}" table. Cannot update ${idField}, ${usernameField}, ${passwordField}, or ${isVerifiedField}.`, + description: `Updates the profile of the currently authenticated user in the "${model}" table. Cannot update ${idField}, ${emailField}, ${passwordField}, or ${isVerifiedField}.`, tags: policy.tags, body: bodySchema, response: responseSchema, diff --git a/ross/src/routes/auth/forgot-password.ts b/ross/src/routes/auth/forgot-password.ts index 0f5dcd5a..75baf89a 100644 --- a/ross/src/routes/auth/forgot-password.ts +++ b/ross/src/routes/auth/forgot-password.ts @@ -21,7 +21,7 @@ export function registerForgotPasswordRoute( return; } - const {model, usernameField} = upAuth; + const {model, emailField} = upAuth; const authModelConfig = models[model]; @@ -40,7 +40,7 @@ export function registerForgotPasswordRoute( app, config, model, - usernameField, + emailField, variant, identifier, policy, @@ -52,13 +52,13 @@ function registerForgotPasswordEndpoint( app: FastifyInstance, config: ResolvedAppConfig, model: string, - usernameField: string, + emailField: string, variant: string, apiIdentifier: string, policy: ResolvedApiPolicy, ): void { const schema: Record = generateSchema( - usernameField, + emailField, model, policy, ); @@ -72,21 +72,18 @@ function registerForgotPasswordEndpoint( config: {apiIdentifier}, }, async (request: FastifyRequest, reply: FastifyReply) => { - const {[usernameField]: username} = request.body as Record< - string, - string - >; + const {[emailField]: email} = request.body as Record; /* c8 ignore start */ - if (!username) { + if (!email) { return reply .status(400) - .send(app.buildResponse(400, `${usernameField} is required`, null)); + .send(app.buildResponse(400, `${emailField} is required`, null)); } /* c8 ignore stop */ - const query = `SELECT * FROM "${model}" WHERE "${usernameField}" = $1 LIMIT 1;`; - const res = await app.db.query(query, [String(username)]); + const query = `SELECT * FROM "${model}" WHERE "${emailField}" = $1 LIMIT 1;`; + const res = await app.db.query(query, [String(email)]); if (res.rows.length === 0) { return reply @@ -107,7 +104,7 @@ function registerForgotPasswordEndpoint( return blocked; } - const userEmail = String(user[usernameField]); + const userEmail = String(user[emailField]); const ulid = await app.otp.sendOTPForVerification(userEmail); return reply.status(200).send( @@ -121,15 +118,15 @@ function registerForgotPasswordEndpoint( } function generateSchema( - usernameField: string, + emailField: string, model: string, policy: ResolvedApiPolicy, ) { const bodySchema = { type: 'object', - required: [usernameField], + required: [emailField], properties: { - [usernameField]: {type: 'string', description: 'The user identifier'}, + [emailField]: {type: 'string', description: 'The user identifier'}, }, additionalProperties: false, }; diff --git a/ross/src/routes/auth/login.ts b/ross/src/routes/auth/login.ts index f0a83743..ee9a469d 100644 --- a/ross/src/routes/auth/login.ts +++ b/ross/src/routes/auth/login.ts @@ -25,7 +25,7 @@ export function registerLoginRoute( return; } - const {model, usernameField, passwordField} = upAuth; + const {model, emailField, passwordField} = upAuth; const authModelConfig = models[model]; @@ -38,7 +38,7 @@ export function registerLoginRoute( app, config, model, - usernameField, + emailField, passwordField, upAuth, variant, @@ -52,7 +52,7 @@ function registerLoginEndpoint( app: FastifyInstance, config: ResolvedAppConfig, model: string, - usernameField: string, + emailField: string, passwordField: string, upAuth: UpAuthRuntime, variant: string, @@ -60,7 +60,7 @@ function registerLoginEndpoint( policy: ResolvedApiPolicy, ): void { const schema: Record = generateSchema( - usernameField, + emailField, passwordField, model, upAuth.mfaRequired ?? false, @@ -76,11 +76,10 @@ function registerLoginEndpoint( config: {apiIdentifier}, }, async (request: FastifyRequest<{Body: ModelBody}>, reply: FastifyReply) => { - const {[usernameField]: username, [passwordField]: password} = - request.body; + const {[emailField]: email, [passwordField]: password} = request.body; - const query = `SELECT * FROM "${model}" WHERE "${usernameField}" = $1 LIMIT 1;`; - const res = await app.db.query(query, [username]); + const query = `SELECT * FROM "${model}" WHERE "${emailField}" = $1 LIMIT 1;`; + const res = await app.db.query(query, [email]); const user = res.rows[0] as Record | undefined; @@ -110,14 +109,14 @@ function registerLoginEndpoint( const {isVerifiedField} = upAuth; - if (isVerifiedField && Boolean(user[isVerifiedField]) !== true) { + if (Boolean(user[isVerifiedField]) !== true) { return reply .status(401) .send(app.buildResponse(401, 'User is not verified', null)); } if (upAuth.mfaRequired) { - const userEmail = String(user[usernameField]); + const userEmail = String(user[emailField]); const ulid = await app.otp.sendOTPForVerification(userEmail); return reply.status(200).send( @@ -143,7 +142,7 @@ function registerLoginEndpoint( app.jwt, config, user, - usernameField, + emailField, rbacUser, ); @@ -164,7 +163,7 @@ function registerLoginEndpoint( } function generateSchema( - usernameField: string, + emailField: string, passwordField: string, model: string, mfaRequired: boolean, @@ -172,9 +171,9 @@ function generateSchema( ) { const bodySchema = { type: 'object', - required: [usernameField, passwordField], + required: [emailField, passwordField], properties: { - [usernameField]: {type: 'string', description: 'The user identifier'}, + [emailField]: {type: 'string', description: 'The user identifier'}, [passwordField]: {type: 'string', description: 'The user password'}, }, additionalProperties: false, diff --git a/ross/src/routes/auth/otp-verify.ts b/ross/src/routes/auth/otp-verify.ts index e7f3b7e7..b1edcc4e 100644 --- a/ross/src/routes/auth/otp-verify.ts +++ b/ross/src/routes/auth/otp-verify.ts @@ -26,7 +26,7 @@ function registerOtpVerifyBase( return; } - const {model, usernameField} = upAuth; + const {model, emailField} = upAuth; const authModelConfig = models[model]; @@ -47,7 +47,7 @@ function registerOtpVerifyBase( app, config, model, - usernameField, + emailField, upAuth, action, path, @@ -62,7 +62,7 @@ function registerOtpVerifyEndpoint( app: FastifyInstance, config: ResolvedAppConfig, model: string, - usernameField: string, + emailField: string, upAuth: UpAuthRuntime, action: 'login' | 'register' | 'forgotPassword', path: string, @@ -71,7 +71,7 @@ function registerOtpVerifyEndpoint( policy: ResolvedApiPolicy, ): void { const schema: Record = generateSchema( - usernameField, + emailField, model, action, policy, @@ -86,24 +86,20 @@ function registerOtpVerifyEndpoint( config: {apiIdentifier}, }, async (request: FastifyRequest<{Body: ModelBody}>, reply: FastifyReply) => { - const {ulid, otp, [usernameField]: username} = request.body; + const {ulid, otp, [emailField]: email} = request.body; /* c8 ignore start */ - if (!ulid || !otp || !username) { + if (!ulid || !otp || !email) { return reply .status(400) .send( - app.buildResponse( - 400, - 'ulid, otp, and username are required', - null, - ), + app.buildResponse(400, 'ulid, otp, and email are required', null), ); } /* c8 ignore stop */ const isValid = await app.otp.verify( - String(username), + String(email), String(otp), String(ulid), ); @@ -129,13 +125,13 @@ function registerOtpVerifyEndpoint( hashedPassword = await hash(String(newPassword)); } - const selectQuery = `SELECT * FROM "${model}" WHERE "${usernameField}" = $1 LIMIT 1;`; + const selectQuery = `SELECT * FROM "${model}" WHERE "${emailField}" = $1 LIMIT 1;`; let tx; try { tx = await app.db.beginTransaction(); - const res = await tx.query(selectQuery, [String(username)]); + const res = await tx.query(selectQuery, [String(email)]); if (res.rows.length === 0) { throw Object.assign(new Error('User not found'), { @@ -146,14 +142,12 @@ function registerOtpVerifyEndpoint( if (action === 'register') { const isVerifiedField = upAuth.isVerifiedField; - if (isVerifiedField) { - const updatedAtClause = buildUpdatedAtClause( - config.data.models[model], - config.infrastructure.database.engine, - ); - const updateQuery = `UPDATE "${model}" SET "${isVerifiedField}" = true${updatedAtClause ? `, ${updatedAtClause}` : ''} WHERE "${usernameField}" = $1;`; - await tx.query(updateQuery, [String(username)]); - } + const updatedAtClause = buildUpdatedAtClause( + config.data.models[model], + config.infrastructure.database.engine, + ); + const updateQuery = `UPDATE "${model}" SET "${isVerifiedField}" = true${updatedAtClause ? `, ${updatedAtClause}` : ''} WHERE "${emailField}" = $1;`; + await tx.query(updateQuery, [String(email)]); await tx.commit(); @@ -168,8 +162,8 @@ function registerOtpVerifyEndpoint( config.data.models[model], config.infrastructure.database.engine, ); - const updateQuery = `UPDATE "${model}" SET "${passwordField}" = $1${updatedAtClause ? `, ${updatedAtClause}` : ''} WHERE "${usernameField}" = $2;`; - await tx.query(updateQuery, [hashedPassword, String(username)]); + const updateQuery = `UPDATE "${model}" SET "${passwordField}" = $1${updatedAtClause ? `, ${updatedAtClause}` : ''} WHERE "${emailField}" = $2;`; + await tx.query(updateQuery, [hashedPassword, String(email)]); await tx.commit(); @@ -197,7 +191,7 @@ function registerOtpVerifyEndpoint( app.jwt, config, user, - usernameField, + emailField, rbacUser, ); @@ -240,7 +234,7 @@ export function registerRegistrationOtpVerifyRoute( } function generateSchema( - usernameField: string, + emailField: string, model: string, action: 'login' | 'register' | 'forgotPassword', policy: ResolvedApiPolicy, @@ -250,15 +244,15 @@ function generateSchema( const bodySchema = { type: 'object', required: isForgotPassword - ? ['ulid', 'otp', usernameField, 'newPassword'] - : ['ulid', 'otp', usernameField], + ? ['ulid', 'otp', emailField, 'newPassword'] + : ['ulid', 'otp', emailField], properties: { ulid: { type: 'string', description: 'The ULID from the OTP send response', }, otp: {type: 'string', description: 'The OTP sent to the user email'}, - [usernameField]: {type: 'string', description: 'The user identifier'}, + [emailField]: {type: 'string', description: 'The user identifier'}, ...(isForgotPassword ? { newPassword: { diff --git a/ross/src/routes/auth/refresh.ts b/ross/src/routes/auth/refresh.ts index ceedc956..79fc028b 100644 --- a/ross/src/routes/auth/refresh.ts +++ b/ross/src/routes/auth/refresh.ts @@ -71,7 +71,7 @@ function resolveTokenFields( const upAuth = getUpAuth(config); if (upAuth) { - return {usernameField: upAuth.usernameField}; + return {usernameField: upAuth.emailField}; } return {}; diff --git a/ross/src/routes/auth/registration.ts b/ross/src/routes/auth/registration.ts index 82598277..61be30f9 100644 --- a/ross/src/routes/auth/registration.ts +++ b/ross/src/routes/auth/registration.ts @@ -25,9 +25,7 @@ export function registerRegistrationRoute( return; } - const {model, passwordField} = upAuth; - const requiresOtp = !!upAuth.isVerifiedField; - const isVerifiedField = upAuth.isVerifiedField; + const {model, passwordField, isVerifiedField} = upAuth; const authModelConfig = models[model]; @@ -44,12 +42,10 @@ export function registerRegistrationRoute( for (const {identifier, variant, policy} of targets) { registerRegistrationEndpoint( app, - config, model, authModelConfig, passwordField, isVerifiedField, - requiresOtp, upAuth, variant, identifier, @@ -60,12 +56,10 @@ export function registerRegistrationRoute( function registerRegistrationEndpoint( app: FastifyInstance, - config: ResolvedAppConfig, model: string, authModelConfig: ModelConfig, passwordField: string, - isVerifiedField: string | undefined, - requiresOtp: boolean, + isVerifiedField: string, upAuth: UpAuthRuntime, variant: string, apiIdentifier: string, @@ -73,9 +67,7 @@ function registerRegistrationEndpoint( ): void { const schema: Record = generateSchema( authModelConfig, - passwordField, model, - requiresOtp, isVerifiedField, policy, ); @@ -108,9 +100,7 @@ function registerRegistrationEndpoint( } /* c8 ignore stop */ - if (isVerifiedField) { - body[isVerifiedField] = false; - } + body[isVerifiedField] = false; const keys = Object.keys(body); const values = Object.values(body); @@ -130,36 +120,17 @@ function registerRegistrationEndpoint( tx?.release(); } - if (requiresOtp) { - const usernameField = upAuth.usernameField; - const userEmail = String(incomingBody[usernameField]); - const ulid = await app.otp.sendOTPForVerification(userEmail); - - return reply - .status(201) - .send( - app.buildResponse( - 201, - 'Registration successful. OTP sent to your email.', - {requiresMfa: true, ulid}, - ), - ); - } - - const responseData: ModelBody = {}; - for (const [k, v] of Object.entries(body)) { - if (k !== passwordField) { - responseData[k] = v; - } - } + const emailField = upAuth.emailField; + const userEmail = String(incomingBody[emailField]); + const ulid = await app.otp.sendOTPForVerification(userEmail); return reply .status(201) .send( app.buildResponse( 201, - `Successfully registered a new user in the ${model} table`, - responseData, + 'Registration successful. OTP sent to your email.', + {requiresMfa: true, ulid}, ), ); }, @@ -168,49 +139,28 @@ function registerRegistrationEndpoint( function generateSchema( authModelConfig: ModelConfig, - passwordField: string, model: string, - requiresOtp: boolean | undefined, - isVerifiedField: string | undefined, + isVerifiedField: string, policy: ResolvedApiPolicy, ) { - const bodyModelConfig = - requiresOtp && isVerifiedField - ? { - ...authModelConfig, - fields: Object.fromEntries( - Object.entries(authModelConfig.fields).filter( - ([name]) => name !== isVerifiedField, - ), - ), - } - : authModelConfig; + const bodyModelConfig = { + ...authModelConfig, + fields: Object.fromEntries( + Object.entries(authModelConfig.fields).filter( + ([name]) => name !== isVerifiedField, + ), + ), + }; const bodySchema = generateJSONValidationSchema(bodyModelConfig, { ignorePrimaryKey: true, additionalProperties: false, excludeTimestamps: true, }); - const responseData = requiresOtp - ? { - type: 'object', - properties: {requiresMfa: {type: 'boolean'}, ulid: {type: 'string'}}, - } - : generateJSONValidationSchema( - { - ...authModelConfig, - fields: Object.fromEntries( - Object.entries(authModelConfig.fields).filter( - ([name]) => name !== passwordField, - ), - ), - }, - { - ignorePrimaryKey: true, - additionalProperties: false, - excludeTimestamps: true, - }, - ); + const responseData = { + type: 'object', + properties: {requiresMfa: {type: 'boolean'}, ulid: {type: 'string'}}, + }; const responseSchema = getResponseStructureSchema([201], responseData); diff --git a/ross/src/routes/auth/resend-otp.ts b/ross/src/routes/auth/resend-otp.ts index 312aadf3..4d969267 100644 --- a/ross/src/routes/auth/resend-otp.ts +++ b/ross/src/routes/auth/resend-otp.ts @@ -22,7 +22,7 @@ function registerResendOtpBase( return; } - const {model, usernameField} = upAuth; + const {model, emailField} = upAuth; const authModelConfig = models[model]; @@ -43,7 +43,7 @@ function registerResendOtpBase( app, config, model, - usernameField, + emailField, action, path, variant, @@ -57,7 +57,7 @@ function registerResendOtpEndpoint( app: FastifyInstance, config: ResolvedAppConfig, model: string, - usernameField: string, + emailField: string, action: string, path: string, variant: string, @@ -65,7 +65,7 @@ function registerResendOtpEndpoint( policy: ResolvedApiPolicy, ): void { const schema: Record = generateSchema( - usernameField, + emailField, model, action, policy, @@ -80,21 +80,18 @@ function registerResendOtpEndpoint( config: {apiIdentifier}, }, async (request: FastifyRequest, reply: FastifyReply) => { - const {[usernameField]: username} = request.body as Record< - string, - string - >; + const {[emailField]: email} = request.body as Record; /* c8 ignore start */ - if (!username) { + if (!email) { return reply .status(400) - .send(app.buildResponse(400, `${usernameField} is required`, null)); + .send(app.buildResponse(400, `${emailField} is required`, null)); } /* c8 ignore stop */ - const query = `SELECT * FROM "${model}" WHERE "${usernameField}" = $1 LIMIT 1;`; - const res = await app.db.query(query, [String(username)]); + const query = `SELECT * FROM "${model}" WHERE "${emailField}" = $1 LIMIT 1;`; + const res = await app.db.query(query, [String(email)]); if (res.rows.length === 0) { return reply @@ -103,7 +100,7 @@ function registerResendOtpEndpoint( } const user = res.rows[0] as Record; - const userEmail = String(user[usernameField]); + const userEmail = String(user[emailField]); const ulid = await app.otp.sendOTPForVerification(userEmail); return reply.status(200).send( @@ -143,16 +140,16 @@ export function registerForgotPasswordResendOtpRoute( } function generateSchema( - usernameField: string, + emailField: string, model: string, action: string, policy: ResolvedApiPolicy, ) { const bodySchema = { type: 'object', - required: [usernameField], + required: [emailField], properties: { - [usernameField]: {type: 'string', description: 'The user identifier'}, + [emailField]: {type: 'string', description: 'The user identifier'}, }, additionalProperties: false, }; diff --git a/ross/src/server.ts b/ross/src/server.ts index f4c14317..8573ea8f 100644 --- a/ross/src/server.ts +++ b/ross/src/server.ts @@ -76,9 +76,7 @@ export async function startServer( const upAuth = getUpAuth(resolvedConfig); const ssoProviders = getSsoProviders(resolvedConfig); - const usesAccountOtp = Boolean( - upAuth && (upAuth.mfaRequired || upAuth.isVerifiedField), - ); + const usesAccountOtp = Boolean(upAuth); const usesCacheSessionStorage = Boolean( resolvedConfig.authentication.enabled && resolvedConfig.authentication.userModel && @@ -201,11 +199,9 @@ export async function startServer( registerLoginResendOtpRoute(app, resolvedConfig); } - if (upAuth.isVerifiedField) { - registerRegistrationOtpVerifyRoute(app, resolvedConfig); - registerRegistrationResendOtpRoute(app, resolvedConfig); - registerEmailChangeRoute(app, resolvedConfig); - } + registerRegistrationOtpVerifyRoute(app, resolvedConfig); + registerRegistrationResendOtpRoute(app, resolvedConfig); + registerEmailChangeRoute(app, resolvedConfig); } }, {prefix: '/api'}, diff --git a/ross/src/validators/config/schema.ts b/ross/src/validators/config/schema.ts index ad31bdcd..869972b2 100644 --- a/ross/src/validators/config/schema.ts +++ b/ross/src/validators/config/schema.ts @@ -712,9 +712,9 @@ const upAuthProviderSchema = { fields: { type: 'object', additionalProperties: false, - required: ['usernameField', 'passwordField'], + required: ['emailField', 'passwordField', 'isVerifiedField'], properties: { - usernameField: { + emailField: { type: 'string', isEntityName: true, minLength: 1, diff --git a/ross/src/validators/config/validate-auth.ts b/ross/src/validators/config/validate-auth.ts index 1258dac0..9b9671dd 100644 --- a/ross/src/validators/config/validate-auth.ts +++ b/ross/src/validators/config/validate-auth.ts @@ -293,11 +293,11 @@ function validateUpAuthProvider( const {fields} = provider.config; const base = '/authentication/providers/up-auth/config'; - const usernameField = assertField( + const emailField = assertField( errors, targetModel, - fields.usernameField, - `${base}/fields/usernameField`, + fields.emailField, + `${base}/fields/emailField`, ); assertField( errors, @@ -306,16 +306,16 @@ function validateUpAuthProvider( `${base}/fields/passwordField`, ); - if (usernameField && usernameField.type !== 'string') { - errors.push(`${base}/fields/usernameField: field must be of type string`); + if (emailField && emailField.type !== 'string') { + errors.push(`${base}/fields/emailField: field must be of type string`); } if (hasSso) { assertNullable( errors, targetModel, - fields.usernameField, - `${base}/fields/usernameField`, + fields.emailField, + `${base}/fields/emailField`, ); assertNullable( errors, @@ -323,36 +323,34 @@ function validateUpAuthProvider( fields.passwordField, `${base}/fields/passwordField`, ); - } else if (usernameField) { - if (!isFieldUnique(targetModel, fields.usernameField, usernameField)) { - errors.push(`${base}/fields/usernameField: field must be unique`); + } else if (emailField) { + if (!isFieldUnique(targetModel, fields.emailField, emailField)) { + errors.push(`${base}/fields/emailField: field must be unique`); } - if (usernameField.nullable !== false) { + if (emailField.nullable !== false) { errors.push( - `${base}/fields/usernameField: field must not be nullable when SSO is not configured`, + `${base}/fields/emailField: field must not be nullable when SSO is not configured`, ); } } - if (fields.isVerifiedField) { - const verifiedField = assertField( - errors, - targetModel, - fields.isVerifiedField, - `${base}/fields/isVerifiedField`, - ); + const verifiedField = assertField( + errors, + targetModel, + fields.isVerifiedField, + `${base}/fields/isVerifiedField`, + ); - if (verifiedField && verifiedField.type !== 'boolean') { - errors.push( - `${base}/fields/isVerifiedField: field must be of type boolean`, - ); - } + if (verifiedField && verifiedField.type !== 'boolean') { + errors.push( + `${base}/fields/isVerifiedField: field must be of type boolean`, + ); + } - if (!config.integrations?.email) { - errors.push( - `${base}/fields/isVerifiedField: integrations.email must be configured when isVerifiedField is set`, - ); - } + if (!config.integrations?.email) { + errors.push( + `${base}/fields/isVerifiedField: integrations.email must be configured when isVerifiedField is set`, + ); } if (provider.config.mfaRequired && !config.integrations?.email) { @@ -428,7 +426,7 @@ function validateSsoProvider( if (columnField.nullable === false && columnField.default === undefined) { const isUpAuthCredential = upAuthProviders.some( p => - p.config.fields.usernameField === columnName || + p.config.fields.emailField === columnName || p.config.fields.passwordField === columnName, ); diff --git a/ross/tests/fixtures/config/__goldens__/full.resolved.json b/ross/tests/fixtures/config/__goldens__/full.resolved.json index 89fb537a..88278de2 100644 --- a/ross/tests/fixtures/config/__goldens__/full.resolved.json +++ b/ross/tests/fixtures/config/__goldens__/full.resolved.json @@ -599,7 +599,7 @@ "type": "up-auth", "config": { "fields": { - "usernameField": "email", + "emailField": "email", "passwordField": "password", "isVerifiedField": "isActive" }, diff --git a/ross/tests/fixtures/config/full.json b/ross/tests/fixtures/config/full.json index 505a9bb4..1677a159 100644 --- a/ross/tests/fixtures/config/full.json +++ b/ross/tests/fixtures/config/full.json @@ -72,7 +72,7 @@ "type": "up-auth", "config": { "fields": { - "usernameField": "email", + "emailField": "email", "passwordField": "password", "isVerifiedField": "isActive" }, diff --git a/ross/tests/helpers/auth-config.ts b/ross/tests/helpers/auth-config.ts index b0218cbe..141f735e 100644 --- a/ross/tests/helpers/auth-config.ts +++ b/ross/tests/helpers/auth-config.ts @@ -23,7 +23,11 @@ export const authModels: Record = { export const upAuthProvider = { type: 'up-auth' as const, config: { - fields: {usernameField: 'email', passwordField: 'password'}, + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, }, }; diff --git a/ross/tests/lib/auth/up-auth.test.ts b/ross/tests/lib/auth/up-auth.test.ts index da060356..b83c9454 100644 --- a/ross/tests/lib/auth/up-auth.test.ts +++ b/ross/tests/lib/auth/up-auth.test.ts @@ -22,14 +22,14 @@ describe('getUpAuth', () => { model: 'users', idField: 'id', providerField: 'provider', - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', mfaRequired: false, }); - expect(upAuth?.isVerifiedField).toBeUndefined(); }); - test('exposes the verification field when configured', () => { + test('exposes the configured verification field', () => { const config = buildEnabledAuth([ { ...upAuthProvider, @@ -66,7 +66,11 @@ describe('getUpAuth', () => { { type: 'up-auth', config: { - fields: {usernameField: 'email', passwordField: 'pw'}, + fields: { + emailField: 'email', + passwordField: 'pw', + isVerifiedField: 'is_active', + }, mfaRequired: false, }, }, diff --git a/ross/tests/lib/config/api.test.ts b/ross/tests/lib/config/api.test.ts index 01c91a0f..a259b453 100644 --- a/ross/tests/lib/config/api.test.ts +++ b/ross/tests/lib/config/api.test.ts @@ -22,8 +22,9 @@ const upAuthAuthentication = { type: 'up-auth' as const, config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/lib/config/redact.test.ts b/ross/tests/lib/config/redact.test.ts index f4babbbb..5260e262 100644 --- a/ross/tests/lib/config/redact.test.ts +++ b/ross/tests/lib/config/redact.test.ts @@ -18,8 +18,9 @@ const upAuth = { type: 'up-auth' as const, config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/lib/config/resolve.test.ts b/ross/tests/lib/config/resolve.test.ts index 371f57bd..0c3b0463 100644 --- a/ross/tests/lib/config/resolve.test.ts +++ b/ross/tests/lib/config/resolve.test.ts @@ -34,8 +34,9 @@ const upAuth = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -871,7 +872,7 @@ test('up-auth is normalized with accessTokenExpiration, refreshTokenExpiration, expect(provider.type).toBe('up-auth'); if (provider.type !== 'up-auth') throw new Error('expected up-auth'); expect(provider.config.mfaRequired).toBe(false); - expect(provider.config.fields.usernameField).toBe('email'); + expect(provider.config.fields.emailField).toBe('email'); expect(getProviderCapabilities(provider)).toContain('password'); expect(getProviderCapabilities(provider)).toContain('register'); }); @@ -895,8 +896,9 @@ test('up-auth explicit accessTokenExpiration, refreshTokenExpiration, sessionSto type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, mfaRequired: true, }, diff --git a/ross/tests/lib/config/route-registry.test.ts b/ross/tests/lib/config/route-registry.test.ts index 4812bd1d..457bde7d 100644 --- a/ross/tests/lib/config/route-registry.test.ts +++ b/ross/tests/lib/config/route-registry.test.ts @@ -52,8 +52,9 @@ const upAuth = { type: 'up-auth' as const, config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'secret_token', + isVerifiedField: 'is_active', }, }, }, @@ -179,10 +180,10 @@ describe('getGeneratedApiIdentifiers', () => { expect(ids.has('auth.v1.users.unknown.otpVerifyLogin')).toBe(true); expect(ids.has('auth.v1.users.unknown.resendOtpLogin')).toBe(true); - expect(ids.has('auth.v1.users.unknown.otpVerifyRegister')).toBe(false); + expect(ids.has('auth.v1.users.unknown.otpVerifyRegister')).toBe(true); }); - test('gates verification auth routes on userModel.isVerifiedField', () => { + test('includes verification auth routes for up-auth', () => { const ids = getGeneratedApiIdentifiers( resolve({ authentication: { diff --git a/ross/tests/lib/schema/response.test.ts b/ross/tests/lib/schema/response.test.ts index e9d00e6f..75e34d0f 100644 --- a/ross/tests/lib/schema/response.test.ts +++ b/ross/tests/lib/schema/response.test.ts @@ -101,7 +101,11 @@ const upAuthProviders = [ name: 'up-auth', capabilities: new Set(['password']), config: { - fields: {usernameField: 'email', passwordField: 'password'}, + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, mfaRequired: false, }, }, diff --git a/ross/tests/lib/server/prevalidation.test.ts b/ross/tests/lib/server/prevalidation.test.ts index c09b602e..434d85f7 100644 --- a/ross/tests/lib/server/prevalidation.test.ts +++ b/ross/tests/lib/server/prevalidation.test.ts @@ -63,8 +63,9 @@ describe('buildPreValidation', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -228,8 +229,9 @@ describe('buildPreValidation', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/migrator/index.test.ts b/ross/tests/migrator/index.test.ts index 12ab2676..4d9845ee 100644 --- a/ross/tests/migrator/index.test.ts +++ b/ross/tests/migrator/index.test.ts @@ -1266,8 +1266,9 @@ describe('migrateDatabase', () => { type: 'up-auth' as const, config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, mfaRequired: false, }, diff --git a/ross/tests/plugin/auth.test.ts b/ross/tests/plugin/auth.test.ts index 06654861..cd2e40b7 100644 --- a/ross/tests/plugin/auth.test.ts +++ b/ross/tests/plugin/auth.test.ts @@ -41,8 +41,9 @@ const upAuthFixture = (): ResolvedAppConfig => type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, mfaRequired: false, }, @@ -109,8 +110,9 @@ describe('Auth Plugin — up-auth engine', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, mfaRequired: false, }, diff --git a/ross/tests/plugin/swagger.test.ts b/ross/tests/plugin/swagger.test.ts index 87acd663..e5cbae04 100644 --- a/ross/tests/plugin/swagger.test.ts +++ b/ross/tests/plugin/swagger.test.ts @@ -75,8 +75,9 @@ describe('Swagger Plugin', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/aggregate.test.ts b/ross/tests/routes/aggregate.test.ts index 79a094a5..b8fc5fc8 100644 --- a/ross/tests/routes/aggregate.test.ts +++ b/ross/tests/routes/aggregate.test.ts @@ -35,8 +35,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/auth-guards.test.ts b/ross/tests/routes/auth-guards.test.ts index 4b4fec87..36a5b34e 100644 --- a/ross/tests/routes/auth-guards.test.ts +++ b/ross/tests/routes/auth-guards.test.ts @@ -87,8 +87,9 @@ describe('auth route registration guards', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/auth-providers.test.ts b/ross/tests/routes/auth-providers.test.ts index 7a63b165..dc055ad2 100644 --- a/ross/tests/routes/auth-providers.test.ts +++ b/ross/tests/routes/auth-providers.test.ts @@ -21,7 +21,13 @@ const dbConfig = { const upAuth = { type: 'up-auth' as const, - config: {fields: {usernameField: 'email', passwordField: 'password'}}, + config: { + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, + }, }; const oauth2 = { diff --git a/ross/tests/routes/auth-sso.test.ts b/ross/tests/routes/auth-sso.test.ts index 251f9e3c..af545660 100644 --- a/ross/tests/routes/auth-sso.test.ts +++ b/ross/tests/routes/auth-sso.test.ts @@ -771,7 +771,13 @@ describe('registerSsoRoutes guards', () => { authenticationWith([ { type: 'up-auth', - config: {fields: {usernameField: 'email', passwordField: 'password'}}, + config: { + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, + }, }, ]), ); diff --git a/ross/tests/routes/change-email.test.ts b/ross/tests/routes/change-email.test.ts index e73420b1..cc2f5d56 100644 --- a/ross/tests/routes/change-email.test.ts +++ b/ross/tests/routes/change-email.test.ts @@ -61,7 +61,7 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, @@ -337,73 +337,6 @@ describe('PATCH /auth/user/email', () => { await app.close(); }); - test('should return 200 without isVerifiedField when not configured', async () => { - const authWithoutVerified: AuthenticationConfig = { - ...upAuthConfig, - jwtSecret: 'this-will-never-be-used', - userModel: { - modelName: 'users', - idField: 'id', - providerField: 'provider', - }, - providers: [ - { - type: 'up-auth', - config: { - fields: { - usernameField: 'email', - passwordField: 'password', - }, - }, - }, - ], - }; - const app = await createChangeEmailApp(authWithoutVerified); - - const token = app.jwt.sign({id: 1, email: 'alice@example.com'}); - - pgClientQueryMock - .mockResolvedValueOnce({rows: [], rowCount: 0}) // BEGIN - .mockResolvedValueOnce({ - // SELECT - rows: [ - { - id: 1, - email: 'alice@example.com', - password: 'hashed', - is_active: true, - }, - ], - rowCount: 1, - }) - .mockResolvedValueOnce({rows: [], rowCount: 1}) // UPDATE - .mockResolvedValueOnce({rows: [], rowCount: 0}); // COMMIT - - const response = await app.inject({ - method: 'PATCH', - url: '/v1/auth/user/email', - headers: { - authorization: `Bearer ${token}`, - }, - payload: {email: 'new@example.com'}, - }); - - expect(response.statusCode).toBe(200); - - // Verify the UPDATE query does NOT include isVerifiedField - const updateCall = pgClientQueryMock.mock.calls.find( - (call: unknown[]) => - typeof call[0] === 'string' && (call[0] as string).includes('UPDATE'), - ); - expect(updateCall).toBeDefined(); - const updateQuery = (updateCall as [string, unknown[]])[0] as string; - expect(updateQuery).toContain('"email" = $1'); - expect(updateQuery).not.toContain('"is_active"'); - expect(updateQuery).toContain('WHERE "id" = $2'); - - await app.close(); - }); - test('should set updated_at when the auth model has an updated_at field', async () => { const modelsWithTimestamps: Record = { users: { diff --git a/ross/tests/routes/change-password.test.ts b/ross/tests/routes/change-password.test.ts index 0a3579ba..90db643e 100644 --- a/ross/tests/routes/change-password.test.ts +++ b/ross/tests/routes/change-password.test.ts @@ -55,8 +55,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/custom-endpoints-function.test.ts b/ross/tests/routes/custom-endpoints-function.test.ts index de65d0f7..a981ec47 100644 --- a/ross/tests/routes/custom-endpoints-function.test.ts +++ b/ross/tests/routes/custom-endpoints-function.test.ts @@ -289,8 +289,9 @@ describe('Custom Function Endpoints Runtime & Execution', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/custom-endpoints.test.ts b/ross/tests/routes/custom-endpoints.test.ts index cee3c63a..103934c5 100644 --- a/ross/tests/routes/custom-endpoints.test.ts +++ b/ross/tests/routes/custom-endpoints.test.ts @@ -54,8 +54,9 @@ describe('test custom-endpoints api', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/delete-me.test.ts b/ross/tests/routes/delete-me.test.ts index 0ba2bfeb..fa3aa9d3 100644 --- a/ross/tests/routes/delete-me.test.ts +++ b/ross/tests/routes/delete-me.test.ts @@ -45,8 +45,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/delete.test.ts b/ross/tests/routes/delete.test.ts index 8f2b1a82..155652c9 100644 --- a/ross/tests/routes/delete.test.ts +++ b/ross/tests/routes/delete.test.ts @@ -58,8 +58,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -340,8 +341,9 @@ describe('test delete api', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/edit-me.test.ts b/ross/tests/routes/edit-me.test.ts index ab7ae9da..f5b5af70 100644 --- a/ross/tests/routes/edit-me.test.ts +++ b/ross/tests/routes/edit-me.test.ts @@ -51,8 +51,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/edit.test.ts b/ross/tests/routes/edit.test.ts index 499dab2f..4435b9bd 100644 --- a/ross/tests/routes/edit.test.ts +++ b/ross/tests/routes/edit.test.ts @@ -23,8 +23,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/forgot-password.test.ts b/ross/tests/routes/forgot-password.test.ts index fccf266b..2e4d3a7f 100644 --- a/ross/tests/routes/forgot-password.test.ts +++ b/ross/tests/routes/forgot-password.test.ts @@ -48,8 +48,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/get-all.test.ts b/ross/tests/routes/get-all.test.ts index 8776e396..d2afa697 100644 --- a/ross/tests/routes/get-all.test.ts +++ b/ross/tests/routes/get-all.test.ts @@ -43,8 +43,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/health.test.ts b/ross/tests/routes/health.test.ts index 0f9cd12c..b1d92223 100644 --- a/ross/tests/routes/health.test.ts +++ b/ross/tests/routes/health.test.ts @@ -423,8 +423,9 @@ describe('Healthcheck Route (GET /api/health)', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/index-route.test.ts b/ross/tests/routes/index-route.test.ts index 649572ef..a7bceda2 100644 --- a/ross/tests/routes/index-route.test.ts +++ b/ross/tests/routes/index-route.test.ts @@ -90,8 +90,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/login.test.ts b/ross/tests/routes/login.test.ts index faad5d83..b282a390 100644 --- a/ross/tests/routes/login.test.ts +++ b/ross/tests/routes/login.test.ts @@ -37,6 +37,7 @@ const authModels: Record = { id: {type: 'integer', primaryKey: true}, email: {type: 'string', nullable: false}, password: {type: 'string', nullable: false}, + isVerified: {type: 'boolean', default: true}, }, }, }; @@ -54,8 +55,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'isVerified', }, }, }, @@ -86,7 +88,7 @@ const upAuthConfigWithVerified: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'isVerified', }, @@ -273,7 +275,12 @@ describe('POST /auth/login', () => { // Mock DB: user exists pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -322,8 +329,9 @@ describe('POST /auth/login', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'isVerified', }, }, }, @@ -333,7 +341,12 @@ describe('POST /auth/login', () => { pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -372,7 +385,12 @@ describe('POST /auth/login', () => { pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -432,6 +450,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, role: 'admin', }, ], @@ -477,6 +496,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, role: ['editor', 'viewer'], }, ], @@ -518,6 +538,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, role: '["editor", "viewer"]', }, ], @@ -559,6 +580,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, role: null, }, ], @@ -612,6 +634,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, }, ], rowCount: 1, @@ -665,6 +688,7 @@ describe('POST /auth/login', () => { id: 1, email: 'alice@example.com', password: 'hashed_password', + isVerified: true, role: 'admin', }, ], @@ -706,8 +730,9 @@ describe('POST /auth/login', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'isVerified', }, mfaRequired: true, }, @@ -718,7 +743,12 @@ describe('POST /auth/login', () => { pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -756,8 +786,9 @@ describe('POST /auth/login', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'isVerified', }, mfaRequired: true, }, @@ -768,7 +799,12 @@ describe('POST /auth/login', () => { pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -819,7 +855,12 @@ describe('POST /auth/login', () => { // Mock DB: user exists pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -916,7 +957,12 @@ describe('POST /auth/login', () => { test('should register admin variant endpoint when apiVariants is configured', async () => { pgQueryMock.mockResolvedValueOnce({ rows: [ - {id: 1, email: 'alice@example.com', password: 'hashed_password'}, + { + id: 1, + email: 'alice@example.com', + password: 'hashed_password', + isVerified: true, + }, ], rowCount: 1, }); @@ -1187,7 +1233,7 @@ describe('POST /auth/login', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'isVerified', }, @@ -1244,7 +1290,7 @@ describe('POST /auth/login', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'isVerified', }, @@ -1286,34 +1332,6 @@ describe('POST /auth/login', () => { await app.close(); }); - test('should allow login when isVerifiedField is not configured, even if user record has isVerified false', async () => { - const app = await createAuthApp(upAuthConfig, authModels); - - pgQueryMock.mockResolvedValueOnce({ - rows: [ - { - id: 1, - email: 'alice@example.com', - password: 'hashed_password', - isVerified: false, - }, - ], - rowCount: 1, - }); - vi.spyOn(bcrypt, 'compare').mockResolvedValue(true as never); - - const response = await app.inject({ - method: 'POST', - url: '/v1/auth/login', - payload: {email: 'alice@example.com', password: 'p@ssw0rd'}, - }); - - expect(response.statusCode).toBe(200); - expect(response.json().data.accessToken).toBeDefined(); - - await app.close(); - }); - test('should reject unverified user on API variant endpoint', async () => { pgQueryMock.mockResolvedValueOnce({ rows: [ @@ -1368,6 +1386,7 @@ describe('POST /auth/login — SSO account guardrail', () => { id: 1, email: 'sso@example.com', password: 'hashed_password', + isVerified: true, provider: 'google', }, ], diff --git a/ross/tests/routes/me.test.ts b/ross/tests/routes/me.test.ts index f57cadce..95f85ee0 100644 --- a/ross/tests/routes/me.test.ts +++ b/ross/tests/routes/me.test.ts @@ -45,8 +45,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/otp-verify.test.ts b/ross/tests/routes/otp-verify.test.ts index 3d24c967..f08061fd 100644 --- a/ross/tests/routes/otp-verify.test.ts +++ b/ross/tests/routes/otp-verify.test.ts @@ -56,7 +56,7 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, @@ -824,68 +824,6 @@ describe('POST /auth/register/verify/otp', () => { await app.close(); }); - - test('should return 200 without UPDATE when isVerifiedField is not configured', async () => { - const authWithoutVerified: AuthenticationConfig = { - ...upAuthConfig, - jwtSecret: 'this-will-never-be-used', - userModel: { - modelName: 'users', - idField: 'id', - providerField: 'provider', - }, - providers: [ - { - type: 'up-auth', - config: { - fields: { - usernameField: 'email', - passwordField: 'password', - }, - }, - }, - ], - }; - const app = await createOtpApp(authWithoutVerified); - - const sendResponse = - await app.otp.sendOTPForVerification('alice@example.com'); - const ulid = typeof sendResponse === 'string' ? sendResponse : ''; - - // Mock transaction: BEGIN, SELECT, COMMIT - pgClientQueryMock - .mockResolvedValueOnce({rows: [], rowCount: 0}) // BEGIN - .mockResolvedValueOnce({ - // SELECT - rows: [{id: 1, email: 'alice@example.com', password: 'hashed'}], - rowCount: 1, - }) - .mockResolvedValueOnce({rows: [], rowCount: 0}); // COMMIT - - vi.spyOn(bcrypt, 'compare').mockResolvedValue(true as never); - - const response = await app.inject({ - method: 'POST', - url: '/v1/auth/register/verify/otp', - payload: {ulid, otp: '000000', email: 'alice@example.com'}, - }); - - expect(response.statusCode).toBe(200); - const body = response.json(); - expect(body.message).toBe('OTP verification successful'); - expect(body.data).toBeNull(); - - // No UPDATE query should have been executed - const updateCall = pgClientQueryMock.mock.calls.find(call => { - const [query] = call; - return ( - typeof query === 'string' && (query as string).includes('UPDATE') - ); - }); - expect(updateCall).toBeUndefined(); - - await app.close(); - }); }); describe('unhappy path', () => { diff --git a/ross/tests/routes/post.test.ts b/ross/tests/routes/post.test.ts index 0d3b8785..22a96461 100644 --- a/ross/tests/routes/post.test.ts +++ b/ross/tests/routes/post.test.ts @@ -33,8 +33,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/rbac-enforcement.test.ts b/ross/tests/routes/rbac-enforcement.test.ts index d9b3462b..2f1bd5c4 100644 --- a/ross/tests/routes/rbac-enforcement.test.ts +++ b/ross/tests/routes/rbac-enforcement.test.ts @@ -46,8 +46,9 @@ describe('RBAC Route-Level PreValidation Enforcement', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/refresh.test.ts b/ross/tests/routes/refresh.test.ts index bb301d41..061e6f65 100644 --- a/ross/tests/routes/refresh.test.ts +++ b/ross/tests/routes/refresh.test.ts @@ -44,7 +44,11 @@ const baseAuth: AuthenticationConfig = { { type: 'up-auth', config: { - fields: {usernameField: 'email', passwordField: 'password'}, + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, }, }, ], diff --git a/ross/tests/routes/registration.test.ts b/ross/tests/routes/registration.test.ts index 44a2b73e..48fe313d 100644 --- a/ross/tests/routes/registration.test.ts +++ b/ross/tests/routes/registration.test.ts @@ -61,8 +61,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -112,8 +113,28 @@ async function createAuthApp( {mode: 'dev'}, ); app.appConfig = config as ResolvedAppConfig; + const cacheStorage = new Map(); + (app as any).cache = { + get: vi.fn(async (key: string) => { + const item = cacheStorage.get(key); + if (!item) return null; + return item.value; + }), + set: vi.fn(async (key: string, value: unknown, ttlSeconds?: number) => { + const expiry = ttlSeconds ? Date.now() + ttlSeconds * 1000 : undefined; + cacheStorage.set(key, {value, expiry}); + }), + delete: vi.fn(async (key: string) => { + cacheStorage.delete(key); + }), + }; + (app as any).communicate = { + sendEmail: vi.fn(async () => {}), + }; + await app.register(databasePlugin); await app.register(responsePlugin); + await app.register(otpPlugin); registerErrorHandler(app); registerNotFoundHandler(app); @@ -221,7 +242,7 @@ describe('POST /auth/register', () => { // ------------------------------------------------------------------------- describe('happy path', () => { - test('should return 201 with the new user data (password excluded)', async () => { + test('should return 201 with requiresMfa and ulid on registration', async () => { const app = await createAuthApp(upAuthConfig); const response = await app.inject({ @@ -238,14 +259,13 @@ describe('POST /auth/register', () => { const body = response.json(); expect(body.code).toBe(201); - expect(body.message).toContain('users'); + expect(body.message).toBe( + 'Registration successful. OTP sent to your email.', + ); expect(body).not.toHaveProperty('raw_data'); - - // data must NOT include the password field - expect(body.data).not.toHaveProperty('password'); expect(body.data).toMatchObject({ - email: 'alice@example.com', - name: 'Alice', + requiresMfa: true, + ulid: expect.any(String), }); await app.close(); @@ -262,7 +282,6 @@ describe('POST /auth/register', () => { }); // bcrypt.hash must have been called with the raw password - expect(hashSpy).toHaveBeenCalledOnce(); expect(hashSpy).toHaveBeenCalledWith('mySecret', 10); hashSpy.mockRestore(); @@ -665,6 +684,7 @@ describe('POST /auth/register', () => { }, username: {type: 'string', nullable: false}, secret: {type: 'string', nullable: false}, + is_active: {type: 'boolean', default: false}, }, }, }; @@ -682,8 +702,9 @@ describe('POST /auth/register', () => { type: 'up-auth', config: { fields: { - usernameField: 'username', + emailField: 'username', passwordField: 'secret', + isVerifiedField: 'is_active', }, }, }, @@ -702,9 +723,11 @@ describe('POST /auth/register', () => { expect(response.statusCode).toBe(201); const body = response.json(); - // The custom password column "secret" must not leak into the response expect(body.data).not.toHaveProperty('secret'); - expect(body.data).toMatchObject({username: 'judy'}); + expect(body.data).toMatchObject({ + requiresMfa: true, + ulid: expect.any(String), + }); const [query] = pgClientQueryMock.mock.calls.find( call => typeof call[0] === 'string' && call[0].includes('INSERT'), @@ -805,7 +828,7 @@ describe('POST /auth/register', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, @@ -851,7 +874,7 @@ describe('POST /auth/register', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, diff --git a/ross/tests/routes/resend-otp.test.ts b/ross/tests/routes/resend-otp.test.ts index 9caa7662..8f2a10bf 100644 --- a/ross/tests/routes/resend-otp.test.ts +++ b/ross/tests/routes/resend-otp.test.ts @@ -52,8 +52,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/routes/search.test.ts b/ross/tests/routes/search.test.ts index 9553e2fc..a71217d5 100644 --- a/ross/tests/routes/search.test.ts +++ b/ross/tests/routes/search.test.ts @@ -65,8 +65,9 @@ const upAuthConfig: AuthenticationConfig = { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/server.test.ts b/ross/tests/server.test.ts index 52cdeeb4..9c5005ac 100644 --- a/ross/tests/server.test.ts +++ b/ross/tests/server.test.ts @@ -843,8 +843,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -889,8 +890,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -925,8 +927,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, mfaRequired: true, }, @@ -958,8 +961,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -994,7 +998,7 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, @@ -1027,8 +1031,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -1070,8 +1075,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -1105,7 +1111,7 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', isVerifiedField: 'is_active', }, @@ -1134,8 +1140,8 @@ describe('Server', () => { expect(registerEmailChangeRoute).toHaveBeenCalled(); }); - it('should not register registration OTP verify route when isVerifiedField is not set', async () => { - const configWithoutVerified: AppConfig = { + it('should register registration OTP verify, resend, and email change routes for up-auth', async () => { + const configWithUpAuth: AppConfig = { ...mockConfig, integrations: { email: { @@ -1155,8 +1161,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -1164,11 +1171,11 @@ describe('Server', () => { }, }; - await startServer(resolve(configWithoutVerified, 'dev')); + await startServer(resolve(configWithUpAuth, 'dev')); - expect(registerRegistrationOtpVerifyRoute).not.toHaveBeenCalled(); - expect(registerRegistrationResendOtpRoute).not.toHaveBeenCalled(); - expect(registerEmailChangeRoute).not.toHaveBeenCalled(); + expect(registerRegistrationOtpVerifyRoute).toHaveBeenCalled(); + expect(registerRegistrationResendOtpRoute).toHaveBeenCalled(); + expect(registerEmailChangeRoute).toHaveBeenCalled(); }); it('should not register login OTP verify route when mfa is not required', async () => { @@ -1192,8 +1199,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -1223,8 +1231,9 @@ describe('Server', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, diff --git a/ross/tests/validators/config.test.ts b/ross/tests/validators/config.test.ts index 1526489a..cf5389ca 100644 --- a/ross/tests/validators/config.test.ts +++ b/ross/tests/validators/config.test.ts @@ -3902,6 +3902,9 @@ const upAuthOnlyModels = { const authBase = () => ({ application: {name: 'Auth Test'}, data: {models: authModels}, + integrations: { + email: {provider: 'dummy'}, + }, authentication: { enabled: true as const, jwtSecret: 'this-is-a-long-enough-secret-key', @@ -3917,7 +3920,11 @@ const authBase = () => ({ const upAuthProvider = { type: 'up-auth', config: { - fields: {usernameField: 'email', passwordField: 'password'}, + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, }, }; @@ -4132,7 +4139,7 @@ describe('validateInvalidAuthConfig', () => { '/authentication/userModel/providerField: field does not exist in model', }, { - name: 'usernameField does not exist in the model', + name: 'emailField does not exist in the model', patch: { authentication: { ...authBase().authentication, @@ -4140,17 +4147,81 @@ describe('validateInvalidAuthConfig', () => { { type: 'up-auth', config: { - fields: {usernameField: 'nope', passwordField: 'password'}, + fields: { + emailField: 'nope', + passwordField: 'password', + isVerifiedField: 'is_active', + }, }, }, ], }, }, expected: - '/authentication/providers/up-auth/config/fields/usernameField: field does not exist in model', + '/authentication/providers/up-auth/config/fields/emailField: field does not exist in model', }, { - name: 'isVerifiedField is not boolean', + name: 'missing emailField in up-auth.fields', + patch: { + authentication: { + ...authBase().authentication, + providers: [ + { + type: 'up-auth', + config: { + fields: { + passwordField: 'password', + isVerifiedField: 'is_active', + }, + }, + }, + ], + }, + }, + expected: "must have required property 'emailField'", + }, + { + name: 'missing passwordField in up-auth.fields', + patch: { + authentication: { + ...authBase().authentication, + providers: [ + { + type: 'up-auth', + config: { + fields: { + emailField: 'email', + isVerifiedField: 'is_active', + }, + }, + }, + ], + }, + }, + expected: "must have required property 'passwordField'", + }, + { + name: 'missing isVerifiedField in up-auth.fields', + patch: { + authentication: { + ...authBase().authentication, + providers: [ + { + type: 'up-auth', + config: { + fields: { + emailField: 'email', + passwordField: 'password', + }, + }, + }, + ], + }, + }, + expected: "must have required property 'isVerifiedField'", + }, + { + name: 'legacy usernameField rejected in up-auth.fields', patch: { authentication: { ...authBase().authentication, @@ -4161,6 +4232,39 @@ describe('validateInvalidAuthConfig', () => { fields: { usernameField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', + }, + }, + }, + ], + }, + }, + expected: 'must NOT have additional properties', + }, + { + name: 'isVerifiedField without email integration', + patch: { + integrations: undefined, + authentication: { + ...authBase().authentication, + providers: [upAuthProvider], + }, + }, + expected: + 'integrations.email must be configured when isVerifiedField is set', + }, + { + name: 'isVerifiedField is not boolean', + patch: { + authentication: { + ...authBase().authentication, + providers: [ + { + type: 'up-auth', + config: { + fields: { + emailField: 'email', + passwordField: 'password', isVerifiedField: 'email', }, }, @@ -4173,13 +4277,18 @@ describe('validateInvalidAuthConfig', () => { { name: 'mfaRequired without email integration', patch: { + integrations: undefined, authentication: { ...authBase().authentication, providers: [ { type: 'up-auth', config: { - fields: {usernameField: 'email', passwordField: 'password'}, + fields: { + emailField: 'email', + passwordField: 'password', + isVerifiedField: 'is_active', + }, mfaRequired: true, }, }, @@ -4327,13 +4436,14 @@ describe('validateInvalidAuthConfig', () => { "field 'tenant_id' must be nullable or have a default because SSO accounts do not set it", }, { - name: 'up-auth usernameField must be string', + name: 'up-auth emailField must be string', models: { users: { fields: { id: {type: 'integer', primaryKey: true}, email: {type: 'integer', unique: true, nullable: false}, password: {type: 'string', nullable: false}, + is_active: {type: 'boolean'}, provider: {type: 'string'}, }, }, @@ -4345,16 +4455,17 @@ describe('validateInvalidAuthConfig', () => { }, }, expected: - '/authentication/providers/up-auth/config/fields/usernameField: field must be of type string', + '/authentication/providers/up-auth/config/fields/emailField: field must be of type string', }, { - name: 'up-auth usernameField must be unique when no SSO', + name: 'up-auth emailField must be unique when no SSO', models: { users: { fields: { id: {type: 'integer', primaryKey: true}, email: {type: 'string', unique: false, nullable: false}, password: {type: 'string', nullable: false}, + is_active: {type: 'boolean'}, provider: {type: 'string'}, }, }, @@ -4366,16 +4477,17 @@ describe('validateInvalidAuthConfig', () => { }, }, expected: - '/authentication/providers/up-auth/config/fields/usernameField: field must be unique', + '/authentication/providers/up-auth/config/fields/emailField: field must be unique', }, { - name: 'up-auth usernameField must not be nullable when no SSO', + name: 'up-auth emailField must not be nullable when no SSO', models: { users: { fields: { id: {type: 'integer', primaryKey: true}, email: {type: 'string', unique: true, nullable: true}, password: {type: 'string', nullable: false}, + is_active: {type: 'boolean'}, provider: {type: 'string'}, }, }, @@ -4387,7 +4499,7 @@ describe('validateInvalidAuthConfig', () => { }, }, expected: - '/authentication/providers/up-auth/config/fields/usernameField: field must not be nullable when SSO is not configured', + '/authentication/providers/up-auth/config/fields/emailField: field must not be nullable when SSO is not configured', }, { name: 'reserved _ross_sessions model name', @@ -4511,6 +4623,7 @@ describe('validateValidAuthConfig', () => { id: {type: 'integer', primaryKey: true}, email: {type: 'string', unique: false, nullable: false}, password: {type: 'string', nullable: false}, + is_active: {type: 'boolean'}, provider: {type: 'string'}, }, indexes: { @@ -4775,7 +4888,11 @@ describe('validateAuthConstraints directly (bypass AJV)', () => { { type: 'up-auth', config: { - fields: {usernameField: 'nope', passwordField: 'password'}, + fields: { + emailField: 'nope', + passwordField: 'password', + isVerifiedField: 'is_active', + }, }, }, oidcProvider, @@ -4786,7 +4903,7 @@ describe('validateAuthConstraints directly (bypass AJV)', () => { const errors = validateAuthConstraints(config as unknown as AppConfig); expect(errors).toContain( - '/authentication/providers/up-auth/config/fields/usernameField: field does not exist in model', + '/authentication/providers/up-auth/config/fields/emailField: field does not exist in model', ); expect(errors.join('\n')).not.toContain('must be nullable'); }); diff --git a/ross/tests/validators/config/validate-rbac.test.ts b/ross/tests/validators/config/validate-rbac.test.ts index 40aa86e4..ab845ca9 100644 --- a/ross/tests/validators/config/validate-rbac.test.ts +++ b/ross/tests/validators/config/validate-rbac.test.ts @@ -28,6 +28,7 @@ const getDefaultModelConfig = (): Record => ({ id: {type: 'integer', primaryKey: true, unique: true, nullable: false}, email: {type: 'string', unique: true, nullable: false}, password: {type: 'string', secret: true, nullable: false}, + is_active: {type: 'boolean'}, provider: {type: 'string', nullable: false}, role: {type: 'string', nullable: false}, status: { @@ -62,6 +63,7 @@ const createBaseConfig = (): AppConfig => ({ }, }, infrastructure: {database: getDefaultDatabaseConfig()}, + integrations: {email: {provider: 'dummy'}}, data: {models: getDefaultModelConfig()}, authentication: { enabled: true, @@ -76,8 +78,9 @@ const createBaseConfig = (): AppConfig => ({ type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, @@ -529,6 +532,7 @@ describe('Static RBAC Constraint Validation (validateRbacConstraints)', () => { const raw: AppConfigInput = { application: {name: 'Full RBAC App'}, infrastructure: {database: getDefaultDatabaseConfig()}, + integrations: {email: {provider: 'dummy'}}, data: {models: getDefaultModelConfig()}, authentication: { enabled: true, @@ -543,8 +547,9 @@ describe('Static RBAC Constraint Validation (validateRbacConstraints)', () => { type: 'up-auth', config: { fields: { - usernameField: 'email', + emailField: 'email', passwordField: 'password', + isVerifiedField: 'is_active', }, }, }, From f2f0479e1944ede827fc1291cce9d1c7f97ef619 Mon Sep 17 00:00:00 2001 From: Abhishek Chatterjee Date: Thu, 26 Nov 2026 23:27:35 +0530 Subject: [PATCH 2/2] feat(ross-docs): #243: update auth docs for emailField and mandatory isVerifiedField --- ross/docs/docs/api-variants.md | 5 +- ross/docs/docs/authentication/introduction.md | 9 +-- ross/docs/docs/authentication/up-auth.md | 57 ++++++++----------- ross/docs/docs/integrations/introduction.md | 12 ++-- ross/docs/docs/rbac.md | 5 +- 5 files changed, 40 insertions(+), 48 deletions(-) diff --git a/ross/docs/docs/api-variants.md b/ross/docs/docs/api-variants.md index b11e7f57..b43cc272 100644 --- a/ross/docs/docs/api-variants.md +++ b/ross/docs/docs/api-variants.md @@ -216,8 +216,9 @@ The following configuration demonstrates a complete setup featuring multi-versio "type": "up-auth", "config": { "fields": { - "usernameField": "email", - "passwordField": "password" + "emailField": "email", + "passwordField": "password", + "isVerifiedField": "is_active" } } } diff --git a/ross/docs/docs/authentication/introduction.md b/ross/docs/docs/authentication/introduction.md index a46be6d1..b5a2901c 100644 --- a/ross/docs/docs/authentication/introduction.md +++ b/ross/docs/docs/authentication/introduction.md @@ -48,8 +48,9 @@ Authentication lives at the top level of your configuration file: "type": "up-auth", "config": { "fields": { - "usernameField": "email", - "passwordField": "password" + "emailField": "email", + "passwordField": "password", + "isVerifiedField": "is_active" } } }, @@ -276,10 +277,10 @@ Auth routes are mounted under the API prefix and variant, so the default base pa | `POST /auth/login` | `up-auth` | | `POST /auth/change-password` | `up-auth` | | `GET`, `PATCH`, `DELETE /auth/user/me` | `up-auth` (these routes also serve SSO-owned rows in a mixed deployment) | -| `PATCH /auth/user/email` | `up-auth` + `fields.isVerifiedField` | +| `PATCH /auth/user/email` | `up-auth` | | `POST /auth/forgot-password` and its `verify/otp` and `resend/otp` routes | `up-auth` + `integrations.email` | | `POST /auth/login/verify/otp` and `/login/resend/otp` | `up-auth` + `mfaRequired: true` | -| `POST /auth/register/verify/otp` and `/register/resend/otp` | `up-auth` + `fields.isVerifiedField` | +| `POST /auth/register/verify/otp` and `/register/resend/otp` | `up-auth` | | `GET /auth/sso//login` and `.../callback` | Each SSO provider | | `POST /auth/sso//token` | An SSO provider with `redirectUrl` | | `GET /auth/sso//metadata` | A SAML provider | diff --git a/ross/docs/docs/authentication/up-auth.md b/ross/docs/docs/authentication/up-auth.md index 5b45e995..e317277a 100644 --- a/ross/docs/docs/authentication/up-auth.md +++ b/ross/docs/docs/authentication/up-auth.md @@ -28,8 +28,9 @@ This is the only provider that owns a password. It also provides registration, p "type": "up-auth", "config": { "fields": { - "usernameField": "email", - "passwordField": "password" + "emailField": "email", + "passwordField": "password", + "isVerifiedField": "is_active" } } } @@ -43,18 +44,18 @@ This is the only provider that owns a password. It also provides registration, p | Field | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `type` | `"up-auth"` | **Yes** | — | Provider identifier. | -| `config.fields.usernameField` | `string` | **Yes** | — | Model column used as the login identifier. It is also the address OTP emails are sent to. | +| `config.fields.emailField` | `string` | **Yes** | — | Model column used as the login identifier. It is also the address OTP emails are sent to. | | `config.fields.passwordField` | `string` | **Yes** | — | Model column that stores the bcrypt hash. Mark it `"secret": true`. | -| `config.fields.isVerifiedField` | `string` | No | — | Boolean model column used for email verification. When set, registration starts unverified and login rejects unverified users. Requires `integrations.email`. | +| `config.fields.isVerifiedField` | `string` | **Yes** | — | Boolean model column used for email verification. Registration starts unverified and login rejects unverified users. Requires `integrations.email`. | | `config.mfaRequired` | `boolean` | No | `false` | Sends an OTP after a correct password and withholds the access token until the OTP is verified. Requires `integrations.email`. | Additional rules enforced at startup: - At most one `up-auth` provider is allowed. - `userModel` and `jwtSecret` are required. -- `usernameField` and `passwordField` must exist in the user model and be of type `string`. -- When no SSO provider is configured, `usernameField` must be unique (`unique: true` or unique index) and not nullable (`nullable: false`), and `passwordField` must not be nullable (`nullable: false`). -- When an SSO provider is configured in the same application, `passwordField` must be `nullable: true` (and `usernameField` must be `nullable: true` unless mapped/provided), because SSO accounts do not have passwords. +- `emailField` and `passwordField` must exist in the user model and be of type `string`. +- When no SSO provider is configured, `emailField` must be unique (`unique: true` or unique index) and not nullable (`nullable: false`), and `passwordField` must not be nullable (`nullable: false`). +- When an SSO provider is configured in the same application, `passwordField` must be `nullable: true` (and `emailField` must be `nullable: true` unless mapped/provided), because SSO accounts do not have passwords. - `isVerifiedField` must exist, must be of type `boolean`, and requires `integrations.email`. - `mfaRequired: true` requires `integrations.email`. @@ -72,13 +73,13 @@ All routes are mounted under the API prefix and variant, so the default base pat | `POST` | `/api/v1/auth/login` | No | `up-auth` configured | | `POST` | `/api/v1/auth/login/verify/otp` | No | `mfaRequired: true` | | `POST` | `/api/v1/auth/login/resend/otp` | No | `mfaRequired: true` | -| `POST` | `/api/v1/auth/register/verify/otp` | No | `isVerifiedField` set | -| `POST` | `/api/v1/auth/register/resend/otp` | No | `isVerifiedField` set | +| `POST` | `/api/v1/auth/register/verify/otp` | No | `up-auth` configured | +| `POST` | `/api/v1/auth/register/resend/otp` | No | `up-auth` configured | | `POST` | `/api/v1/auth/forgot-password` | No | `integrations.email` | | `POST` | `/api/v1/auth/forgot-password/verify/otp` | No | `integrations.email` | | `POST` | `/api/v1/auth/forgot-password/resend/otp` | No | `integrations.email` | | `POST` | `/api/v1/auth/change-password` | Bearer JWT | `up-auth` configured | -| `PATCH` | `/api/v1/auth/user/email` | Bearer JWT | `isVerifiedField` set | +| `PATCH` | `/api/v1/auth/user/email` | Bearer JWT | `up-auth` configured | | `GET` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured | | `PATCH` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured | | `DELETE` | `/api/v1/auth/user/me` | Bearer JWT | `up-auth` configured | @@ -103,24 +104,10 @@ The request body is generated from the user model: - The primary key and managed timestamp columns are excluded. - Every non-nullable field without a default is required. - Unknown properties are rejected. -- When `isVerifiedField` is configured, that column is removed from the accepted body and forced to `false`. +- `isVerifiedField` is removed from the accepted body and forced to `false`. - The password is hashed before the row is inserted. -Success (no verification configured): - -```json -{ - "code": 201, - "message": "Successfully registered a new user in the users table", - "data": { - "email": "alice@example.com", - "display_name": "Alice", - "provider": "up-auth" - } -} -``` - -Success with `isVerifiedField` configured: +Success: ```json { @@ -178,7 +165,7 @@ Complete the login with `POST /auth/login/verify/otp` and the `ulid`, `otp`, and | --- | --- | --- | | `400` | `Password management is not supported for accounts authenticated via ...` | The matched row belongs to an SSO provider. | | `401` | `Invalid username or password` | Unknown user or wrong password. | -| `401` | `User is not verified` | `isVerifiedField` is set and the column is not `true`. | +| `401` | `User is not verified` | The `isVerifiedField` column is not `true`. | | `400` | Schema validation message | Missing or unknown body properties. | The handler compares against a dummy hash when the user does not exist, so response timing does not reveal whether an account is registered. @@ -315,7 +302,7 @@ The route always requires a bearer token, independently of the `apis` authorizat ## Change email -Available only when `fields.isVerifiedField` is configured. It updates the email column, marks the account unverified, and sends an OTP to the new address: +Updates the email column, marks the account unverified, and sends an OTP to the new address: ```http PATCH /api/v1/auth/user/email @@ -369,9 +356,9 @@ Content-Type: application/json The accepted body is generated from the model with these columns removed: - the primary key (`idField`) -- the username column (`usernameField`) +- the email column (`emailField`) - the password column (`passwordField`) -- the verification column (`isVerifiedField`, when configured) +- the verification column (`isVerifiedField`) - managed timestamp columns An empty body returns `400 No editable fields provided`. Success returns the updated fields: @@ -416,7 +403,7 @@ Deletion runs inside a transaction. The row is removed permanently; ROSS does no | Claim | Source | | --- | --- | | `id` | `userModel.idField` | -| `` | The username column, when it has a value | +| `` | The email column, when it has a value | | `role` | `rbac.roleField` when RBAC is enabled and the value is a scalar | | `roles` | `rbac.roleField` when the value is an array or a JSON-encoded array | | `iat`, `exp` | Issued-at and `accessTokenExpiration` | @@ -448,7 +435,7 @@ Deletion runs inside a transaction. The row is removed permanently; ROSS does no "type": "up-auth", "config": { "fields": { - "usernameField": "email", + "emailField": "email", "passwordField": "password", "isVerifiedField": "is_active" }, @@ -484,7 +471,11 @@ Password login and SSO can coexist. Make the credential columns nullable and let { "type": "up-auth", "config": { - "fields": {"usernameField": "email", "passwordField": "password"} + "fields": { + "emailField": "email", + "passwordField": "password", + "isVerifiedField": "is_active" + } } }, { diff --git a/ross/docs/docs/integrations/introduction.md b/ross/docs/docs/integrations/introduction.md index af9ae387..1bd5e576 100644 --- a/ross/docs/docs/integrations/introduction.md +++ b/ross/docs/docs/integrations/introduction.md @@ -49,8 +49,8 @@ ROSS sends email only for account and security flows that are driven by one-time | --- | --- | --- | | Forgot password | `POST /api/v1/auth/forgot-password`, `/forgot-password/verify/otp`, `/forgot-password/resend/otp` | `integrations.email` is configured | | Login MFA | `POST /api/v1/auth/login`, `/login/verify/otp`, `/login/resend/otp` | `integrations.email` and the `up-auth` provider has `config.mfaRequired: true` | -| Registration verification | `POST /api/v1/auth/register`, `/register/verify/otp`, `/register/resend/otp` | `integrations.email` and the `up-auth` provider has `config.fields.isVerifiedField` set | -| Email change | `PATCH /api/v1/auth/user/email` | `integrations.email` and `config.fields.isVerifiedField` is set | +| Registration verification | `POST /api/v1/auth/register`, `/register/verify/otp`, `/register/resend/otp` | `integrations.email` and `up-auth` is configured | +| Email change | `PATCH /api/v1/auth/user/email` | `integrations.email` and `up-auth` is configured | Each OTP email contains: @@ -72,16 +72,14 @@ It depends on your authentication configuration: | Your authentication setup | Email integration | | --- | --- | -| Authentication disabled | Not needed | -| `up-auth` without `mfaRequired` and without `isVerifiedField` | Optional, but required for forgot-password | -| `up-auth` with `mfaRequired: true` | **Required** (validation fails otherwise) | -| `up-auth` with `config.fields.isVerifiedField` set | **Required** (validation fails otherwise) | +| Authentication disabled or SSO-only | Not needed | +| `up-auth` (with or without `mfaRequired: true`) | **Required** (validation fails otherwise) | If you omit `integrations.email`: - ROSS does not register the `communicate` plugin or the `app.communicate` decorator. - Email-dependent routes are not mounted, so requests to them return `404 Not Found`. -- Configuration validation rejects `mfaRequired: true` and `isVerifiedField` with an explicit error that the integration must be configured. +- Configuration validation rejects `up-auth` (`isVerifiedField` and `mfaRequired: true`) with an explicit error that the integration must be configured. ## Secrets and environment variables diff --git a/ross/docs/docs/rbac.md b/ross/docs/docs/rbac.md index bc4baa81..9776b65e 100644 --- a/ross/docs/docs/rbac.md +++ b/ross/docs/docs/rbac.md @@ -290,8 +290,9 @@ Here is an end-to-end example configuring models, authentication, role hierarchi "type": "up-auth", "config": { "fields": { - "usernameField": "email", - "passwordField": "password" + "emailField": "email", + "passwordField": "password", + "isVerifiedField": "is_active" } } }