diff --git a/packages/core/src/lib/user.ts b/packages/core/src/lib/user.ts index 5b397f439..18a737572 100644 --- a/packages/core/src/lib/user.ts +++ b/packages/core/src/lib/user.ts @@ -44,6 +44,7 @@ export const findUserByUsernameAndPassword = async ( password: string ): Promise => { const user = await findUserByUsername(username); + assertThat(user, 'user.username_not_exists'); const { passwordEncrypted, passwordEncryptionMethod } = user; assertThat(passwordEncrypted && passwordEncryptionMethod, 'session.invalid_sign_in_method'); diff --git a/packages/core/src/queries/user.ts b/packages/core/src/queries/user.ts index 83ad9bdc7..16e5e2e1b 100644 --- a/packages/core/src/queries/user.ts +++ b/packages/core/src/queries/user.ts @@ -10,7 +10,7 @@ import { DeletionError, UpdateError } from '@/errors/SlonikError'; const { table, fields } = convertToIdentifiers(Users); export const findUserByUsername = async (username: string) => - envSet.pool.one(sql` + envSet.pool.maybeOne(sql` select ${sql.join(Object.values(fields), sql`,`)} from ${table} where ${fields.username}=${username} diff --git a/packages/core/src/routes/session.ts b/packages/core/src/routes/session.ts index ad7d44ec3..8061098e8 100644 --- a/packages/core/src/routes/session.ts +++ b/packages/core/src/routes/session.ts @@ -67,15 +67,14 @@ export default function sessionRoutes(router: T, prov '/session/sign-in/username-password', koaGuard({ body: object({ - username: string(), - password: string(), + username: string().nonempty(), + password: string().nonempty(), }), }), async (ctx, next) => { const { username, password } = ctx.guard.body; const type = 'SignInUsernamePassword'; ctx.log(type, { username }); - assertThat(password, 'session.insufficient_info'); const { id } = await findUserByUsernameAndPassword(username, password); ctx.log(type, { userId: id }); diff --git a/packages/phrases/src/locales/en.ts b/packages/phrases/src/locales/en.ts index aff4ca61e..d71f97666 100644 --- a/packages/phrases/src/locales/en.ts +++ b/packages/phrases/src/locales/en.ts @@ -89,7 +89,7 @@ const translation = { invalid_passcode: 'The passcode is invalid.', invalid_connector_auth: 'The authorization is invalid.', invalid_connector_request: 'The connector data is invalid.', - request: 'Request error {{message}}', + request: 'Request error: {{message}}', unknown: 'Unknown error, please try again later.', invalid_session: 'Session not found. Please go back and sign in again.', }, @@ -585,6 +585,7 @@ const errors = { phone_exists_register: 'The phone number has been registered.', invalid_email: 'Invalid email address.', invalid_phone: 'Invalid phone number.', + username_not_exists: 'The username has not been registered yet.', email_not_exists: 'The email address has not been registered yet.', phone_not_exists: 'The phone number has not been registered yet.', identity_not_exists: 'The social account has not been registered yet.', @@ -603,7 +604,7 @@ const errors = { connector_id_mismatch: 'The connectorId is mismatched with session record.', connector_session_not_found: 'Connector session not found. Please go back and sign in again.', unauthorized: 'Please sign in first.', - unsupported_prompt_name: 'Unsupported prompt name', + unsupported_prompt_name: 'Unsupported prompt name.', }, connector: { general: 'An unexpected error occurred in connector.', @@ -646,7 +647,7 @@ const errors = { create_failed: 'Failed to create {{name}}.', not_exists: 'The {{name}} does not exist.', not_exists_with_id: 'The {{name}} with ID `{{id}}` does not exist.', - not_found: 'The resource does not exist', + not_found: 'The resource does not exist.', }, }; diff --git a/packages/phrases/src/locales/zh-cn.ts b/packages/phrases/src/locales/zh-cn.ts index 91ca32fc6..e6c77bedb 100644 --- a/packages/phrases/src/locales/zh-cn.ts +++ b/packages/phrases/src/locales/zh-cn.ts @@ -89,7 +89,7 @@ const translation = { invalid_passcode: '无效的验证码。', invalid_connector_auth: '登录失败。', invalid_connector_request: '无效的登录请求。', - request: '请求错误:{{ message }}。', + request: '请求错误:{{ message }}', // All error messages end with '。'. unknown: '未知错误,请稍后重试。', invalid_session: '未找到有效的会话,请重新登录。', }, @@ -579,6 +579,7 @@ const errors = { phone_exists_register: '手机号码已被注册。', invalid_email: '邮箱地址不正确。', invalid_phone: '手机号码不正确。', + username_not_exists: '用户名尚未注册。', email_not_exists: '邮箱地址尚未注册。', phone_not_exists: '手机号码尚未注册。', identity_not_exists: '该社交账号尚未注册。', @@ -638,7 +639,7 @@ const errors = { create_failed: '创建 {{name}} 失败。', not_exists: '该 {{name}} 不存在。', not_exists_with_id: 'ID 为 `{{id}}` 的 {{name}} 不存在。', - not_found: '该资源不存在', + not_found: '该资源不存在。', }, };