fix admin login issue
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 54s
Build & Push / Build & Push Docker Image (push) Successful in 3m29s
Test / API Unit Tests (push) Successful in 1m14s
Test / Homepage Unit Tests (push) Successful in 48s
Test / Carplace Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 44s
Test / API Integration Tests (push) Successful in 1m8s
Build & Push / Pipeline Tests (push) Successful in 1m53s
Test / Type Check (all packages) (push) Successful in 54s
Build & Push / Build & Push Docker Image (push) Successful in 3m29s
Test / API Unit Tests (push) Successful in 1m14s
Test / Homepage Unit Tests (push) Successful in 48s
Test / Carplace Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 40s
Test / Dashboard Unit Tests (push) Successful in 44s
Test / API Integration Tests (push) Successful in 1m8s
This commit is contained in:
@@ -140,12 +140,8 @@ export async function login(email: string, password: string, totpCode?: string,
|
||||
const valid = await bcrypt.compare(password, admin.passwordHash)
|
||||
if (!valid) return null
|
||||
|
||||
if (admin.totpEnabled) {
|
||||
if (!totpCode && !recoveryCode) {
|
||||
if (!admin.totpSecret) await sendAdminEmailOtp(admin)
|
||||
return { totpRequired: true, method: admin.totpSecret ? 'authenticator' : 'email' } as const
|
||||
}
|
||||
|
||||
let last2faAt: number | undefined
|
||||
if (admin.totpEnabled && (totpCode || recoveryCode)) {
|
||||
const validTotp = totpCode && admin.totpSecret
|
||||
? authenticator.verify({ token: totpCode, secret: admin.totpSecret! })
|
||||
: false
|
||||
@@ -154,9 +150,8 @@ export async function login(email: string, password: string, totpCode?: string,
|
||||
? await consumeAdminRecoveryCode(admin.id, recoveryCode)
|
||||
: false
|
||||
|
||||
if (!validTotp && !validEmailOtp && !validRecoveryCode) {
|
||||
return { invalidTotp: true } as const
|
||||
}
|
||||
if (!validTotp && !validEmailOtp && !validRecoveryCode) return { invalidTotp: true } as const
|
||||
last2faAt = Date.now()
|
||||
}
|
||||
|
||||
await repo.updateAdminLastLogin(admin.id)
|
||||
@@ -167,7 +162,7 @@ export async function login(email: string, password: string, totpCode?: string,
|
||||
resourceId: admin.id,
|
||||
})
|
||||
|
||||
return presenter.presentAdminSession(admin, signAdminToken(admin.id, admin.totpEnabled ? Date.now() : undefined))
|
||||
return presenter.presentAdminSession(admin, signAdminToken(admin.id, last2faAt))
|
||||
}
|
||||
|
||||
export async function setupTotp(adminId: string, email: string) {
|
||||
|
||||
Reference in New Issue
Block a user