Remove all references to 'Guest' user type from the codebase, simplifying the role system to only support 'Admin' and 'User' roles. Changes: - Update type definitions to exclude 'Guest' from UserType - Remove isGuest() method from SessionManager - Remove Guest-specific logic from update services - Update all type assertions from 'Admin | User | Guest' to 'Admin | User' - Remove Guest UI styling from UserSelectionDialog - Replace Guest fallback with ValidationError in settings handler Error handling: - Zod schema now rejects 'Guest' as invalid user type - TypeScript will fail compilation if 'Guest' is referenced - Runtime errors occur if database contains Guest users No database migration needed (confirmed: no Guest users exist) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
/**
|
|
* Zod schemas for Authentication module validation
|
|
*/
|
|
|
|
import { z } from 'zod'
|
|
|
|
/**
|
|
* Schema for login request validation
|
|
*/
|
|
export const LoginRequestSchema = z.object({
|
|
username: z.string().min(1, 'Username is required'),
|
|
password: z.string().min(1, 'Password is required')
|
|
})
|
|
|
|
export type LoginRequestZod = z.infer<typeof LoginRequestSchema>
|
|
|
|
/**
|
|
* Schema for user info validation
|
|
*/
|
|
export const UserInfoSchema = z.object({
|
|
id: z.number().int().positive(),
|
|
username: z.string().min(1),
|
|
userType: z.enum(['Admin', 'User']),
|
|
computerName: z.string().optional()
|
|
})
|
|
|
|
export type UserInfoZod = z.infer<typeof UserInfoSchema>
|
|
|
|
/**
|
|
* Validate login request
|
|
*/
|
|
export function validateLoginRequest(input: unknown): {
|
|
success: boolean
|
|
data?: LoginRequestZod
|
|
error?: string
|
|
} {
|
|
const result = LoginRequestSchema.safeParse(input)
|
|
if (result.success) {
|
|
return { success: true, data: result.data }
|
|
}
|
|
return {
|
|
success: false,
|
|
error: result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join('; ')
|
|
}
|
|
}
|