mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +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 &&
|
obj !== null &&
|
||||||
'user' in obj &&
|
'user' in obj &&
|
||||||
isUser(obj.user) &&
|
isUser(obj.user) &&
|
||||||
'sessionId' in obj &&
|
(!('sessionId' in obj) ||
|
||||||
typeof (obj as LoginResponse).sessionId === 'string' &&
|
typeof (obj as LoginResponse).sessionId === 'string') &&
|
||||||
'expiresAt' in obj &&
|
(!('expiresAt' in obj) ||
|
||||||
typeof (obj as LoginResponse).expiresAt === 'string'
|
typeof (obj as LoginResponse).expiresAt === 'string')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ export enum UserRole {
|
|||||||
* Type guard to check if a value is a valid UserRole
|
* Type guard to check if a value is a valid UserRole
|
||||||
*/
|
*/
|
||||||
export function isUserRole(value: unknown): value is 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 {
|
export enum Theme {
|
||||||
|
|||||||
Reference in New Issue
Block a user