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:
@@ -1,14 +1,10 @@
|
||||
import type { H3Event } from 'h3'
|
||||
|
||||
import type { UserRole } from '~~/shared/auth'
|
||||
import { normalizeUsername, type UserRole } from '~~/shared/auth'
|
||||
|
||||
import { createUserSession, destroyUserSession, getUserSession } from './session'
|
||||
import { getUserById, updateLastLogin, type UserAuthRecord } from './user-repository'
|
||||
|
||||
export function normalizeUsername(value: string) {
|
||||
return value.trim().toLowerCase()
|
||||
}
|
||||
|
||||
export async function getAuthContext(event: H3Event): Promise<{
|
||||
session: Awaited<ReturnType<typeof getUserSession>>
|
||||
user: UserAuthRecord
|
||||
|
||||
Reference in New Issue
Block a user