refactor: centralize validation, error handling, and formatting logic

Extract shared auth logic and validation rules to shared/auth.ts
Introduce utility functions for HTTP errors and user input parsing
Standardize error messages and date formatting across the app
This commit is contained in:
2026-04-12 20:29:39 +08:00
parent 377a9617be
commit 07e5d42005
23 changed files with 294 additions and 267 deletions

View File

@@ -56,11 +56,7 @@ export interface PasskeyRecord {
lastUsedAt: string | null
}
function parseCount(value: number | string): number {
return typeof value === 'number' ? value : Number.parseInt(value, 10)
}
function parseCounter(value: number | string): number {
function parseInteger(value: number | string): number {
return typeof value === 'number' ? value : Number.parseInt(value, 10)
}
@@ -78,7 +74,7 @@ function parseTransports(value: AuthenticatorTransportFuture[] | string): Authen
}
function mapAuthUser(row: DbUserRow): AuthUser {
const passkeyCount = parseCount(row.passkey_count)
const passkeyCount = parseInteger(row.passkey_count)
return {
id: row.id,
@@ -116,7 +112,7 @@ function mapPasskeyRecord(row: DbPasskeyRow): PasskeyRecord {
userId: row.user_id,
credentialId: row.credential_id,
publicKey: row.public_key,
counter: parseCounter(row.counter),
counter: parseInteger(row.counter),
deviceType: row.device_type,
backedUp: row.backed_up,
transports: parseTransports(row.transports),