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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user