mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
28 lines
602 B
TypeScript
28 lines
602 B
TypeScript
import { UserDto } from '#dtos/user';
|
|
import User from '#models/user';
|
|
|
|
export class UserAuthDto {
|
|
declare isAuthenticated: boolean;
|
|
declare isAdmin: boolean;
|
|
declare user?: UserDto;
|
|
|
|
constructor(user: User | undefined) {
|
|
if (!user) return;
|
|
this.isAuthenticated = !!user;
|
|
this.isAdmin = user?.isAdmin;
|
|
this.user = user && new UserDto(user);
|
|
}
|
|
|
|
serialize(): {
|
|
isAuthenticated: boolean;
|
|
isAdmin: boolean;
|
|
user: ReturnType<UserDto['serialize']> | undefined;
|
|
} {
|
|
return {
|
|
isAuthenticated: this.isAuthenticated,
|
|
isAdmin: this.isAdmin,
|
|
user: this.user?.serialize(),
|
|
};
|
|
}
|
|
}
|