mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Refactor type guards for LoginResponse and UserRole to improve validation logic
This commit is contained in:
@@ -42,10 +42,10 @@ export function isLoginResponse(obj: unknown): obj is LoginResponse {
|
||||
obj !== null &&
|
||||
'user' in obj &&
|
||||
isUser(obj.user) &&
|
||||
'sessionId' in obj &&
|
||||
typeof (obj as LoginResponse).sessionId === 'string' &&
|
||||
'expiresAt' in obj &&
|
||||
typeof (obj as LoginResponse).expiresAt === 'string'
|
||||
(!('sessionId' in obj) ||
|
||||
typeof (obj as LoginResponse).sessionId === 'string') &&
|
||||
(!('expiresAt' in obj) ||
|
||||
typeof (obj as LoginResponse).expiresAt === 'string')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,10 @@ export enum UserRole {
|
||||
* Type guard to check if a value is a valid UserRole
|
||||
*/
|
||||
export function isUserRole(value: unknown): value is UserRole {
|
||||
return typeof value === 'string' && value in UserRole;
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
Object.values(UserRole).includes(value as UserRole)
|
||||
);
|
||||
}
|
||||
|
||||
export enum Theme {
|
||||
|
||||
Reference in New Issue
Block a user