inital
This commit is contained in:
50
backend/src/types/auth.types.ts
Normal file
50
backend/src/types/auth.types.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export interface TokenResponse {
|
||||
access_token: string;
|
||||
token_type: string;
|
||||
expires_in: number;
|
||||
refresh_token?: string;
|
||||
id_token?: string;
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
sub: string;
|
||||
email: string;
|
||||
email_verified?: boolean;
|
||||
name?: string;
|
||||
preferred_username?: string;
|
||||
given_name?: string;
|
||||
family_name?: string;
|
||||
picture?: string;
|
||||
groups?: string[];
|
||||
}
|
||||
|
||||
export interface AuthRequest {
|
||||
code: string;
|
||||
state?: string;
|
||||
}
|
||||
|
||||
export interface JwtPayload {
|
||||
userId: string; // UUID
|
||||
email: string;
|
||||
authentikSub: string;
|
||||
iat?: number;
|
||||
exp?: number;
|
||||
}
|
||||
|
||||
export interface RefreshTokenPayload {
|
||||
userId: string; // UUID
|
||||
email: string;
|
||||
iat?: number;
|
||||
exp?: number;
|
||||
}
|
||||
|
||||
export interface AuthenticatedUser {
|
||||
id: string; // UUID
|
||||
email: string;
|
||||
authentikSub: string;
|
||||
name?: string;
|
||||
username?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
92
backend/src/types/user.types.ts
Normal file
92
backend/src/types/user.types.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* User entity matching database schema
|
||||
*/
|
||||
export interface User {
|
||||
id: string;
|
||||
authentik_sub: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
preferred_username: string | null;
|
||||
given_name: string | null;
|
||||
family_name: string | null;
|
||||
profile_picture_url: string | null;
|
||||
|
||||
refresh_token: string | null;
|
||||
refresh_token_expires_at: Date | null;
|
||||
|
||||
last_login_at: Date | null;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
|
||||
preferences: Record<string, any>;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* DTO for creating a new user
|
||||
*/
|
||||
export interface CreateUserDTO {
|
||||
authentik_sub: string;
|
||||
email: string;
|
||||
name?: string;
|
||||
preferred_username?: string;
|
||||
given_name?: string;
|
||||
family_name?: string;
|
||||
profile_picture_url?: string;
|
||||
preferences?: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* DTO for updating an existing user
|
||||
*/
|
||||
export interface UpdateUserDTO {
|
||||
name?: string;
|
||||
preferred_username?: string;
|
||||
given_name?: string;
|
||||
family_name?: string;
|
||||
profile_picture_url?: string;
|
||||
refresh_token?: string | null;
|
||||
refresh_token_expires_at?: Date | null;
|
||||
last_login_at?: Date;
|
||||
preferences?: Record<string, any>;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* User response without sensitive fields
|
||||
* Used for API responses
|
||||
*/
|
||||
export interface UserResponse {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
preferred_username: string | null;
|
||||
given_name: string | null;
|
||||
family_name: string | null;
|
||||
profile_picture_url: string | null;
|
||||
last_login_at: Date | null;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
preferences: Record<string, any>;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert User to UserResponse by removing sensitive fields
|
||||
*/
|
||||
export function toUserResponse(user: User): UserResponse {
|
||||
return {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
preferred_username: user.preferred_username,
|
||||
given_name: user.given_name,
|
||||
family_name: user.family_name,
|
||||
profile_picture_url: user.profile_picture_url,
|
||||
last_login_at: user.last_login_at,
|
||||
created_at: user.created_at,
|
||||
updated_at: user.updated_at,
|
||||
preferences: user.preferences,
|
||||
is_active: user.is_active,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user