base commit

This commit is contained in:
@kirill.komarov
2026-05-10 14:38:32 +05:00
parent 5ddde15fd3
commit f56d6a79fb
6 changed files with 141 additions and 4 deletions
+15
View File
@@ -29,7 +29,22 @@ export async function issueEmailCode({ email, purpose, userId = null }) {
await sendLoginCodeEmail({ to: email, code })
}
function parseEnvBool(raw) {
const v = String(raw ?? '').trim().toLowerCase()
return v === 'true' || v === '1' || v === 'yes'
}
/** Тестовые стенды: принять код из переменной DEFAULT_CODE без записи в БД. */
export function isDefaultLoginCodeAccepted(codeInput) {
if (!parseEnvBool(process.env.IS_DEFAULT_CODE_ENABLED)) return false
const expected = String(process.env.DEFAULT_CODE ?? '').trim()
if (!expected || expected.length < 4) return false
return String(codeInput ?? '').trim() === expected
}
export async function verifyEmailCode({ email, purpose, code, userId = null }) {
if (purpose === 'login' && isDefaultLoginCodeAccepted(code)) return true
const now = new Date()
const codeHash = sha256(`${email}:${purpose}:${code}:${userId ?? ''}`)