Refactor code structure and remove redundant changes

This commit is contained in:
pacnpal
2025-11-09 16:31:34 -05:00
parent 2884bc23ce
commit eb68cf40c6
1080 changed files with 27361 additions and 56687 deletions

206
lib/types/auth.ts Normal file
View File

@@ -0,0 +1,206 @@
/**
* Authentication Type Definitions
*
* Types for user authentication, registration, and profile management.
* These types align with the Django backend API schemas.
*/
// ============================================================================
// User Types
// ============================================================================
export interface User {
id: string;
email: string;
username: string;
first_name: string;
last_name: string;
display_name: string;
avatar_url: string | null;
bio: string | null;
reputation_score: number;
mfa_enabled: boolean;
banned: boolean;
date_joined: string;
last_login: string | null;
oauth_provider: string;
}
export interface UserProfile extends User {
// Extended profile fields
role?: UserRole;
permissions?: UserPermissions;
stats?: UserStats;
preferences?: UserPreferences;
}
export interface UserRole {
role: 'user' | 'moderator' | 'admin';
is_moderator: boolean;
is_admin: boolean;
granted_at: string;
granted_by_email: string | null;
}
export interface UserPermissions {
can_submit: boolean;
can_moderate: boolean;
can_admin: boolean;
can_edit_own: boolean;
can_delete_own: boolean;
}
export interface UserStats {
total_submissions: number;
approved_submissions: number;
reputation_score: number;
member_since: string;
last_active: string | null;
}
export interface UserPreferences {
email_notifications: boolean;
email_on_submission_approved: boolean;
email_on_submission_rejected: boolean;
profile_public: boolean;
show_email: boolean;
}
// ============================================================================
// Authentication Request/Response Types
// ============================================================================
export interface LoginCredentials {
email: string;
password: string;
mfa_token?: string;
}
export interface RegisterData {
email: string;
password: string;
password_confirm: string;
username?: string;
first_name?: string;
last_name?: string;
}
export interface AuthResponse {
access: string;
refresh: string;
token_type: string;
}
export interface AuthTokens {
accessToken: string;
refreshToken: string;
}
export interface ChangePasswordData {
old_password: string;
new_password: string;
new_password_confirm: string;
}
export interface ResetPasswordData {
email: string;
}
export interface ResetPasswordConfirmData {
token: string;
password: string;
password_confirm: string;
}
export interface UpdateProfileData {
first_name?: string;
last_name?: string;
username?: string;
bio?: string;
avatar_url?: string;
}
export interface UpdatePreferencesData {
email_notifications?: boolean;
email_on_submission_approved?: boolean;
email_on_submission_rejected?: boolean;
profile_public?: boolean;
show_email?: boolean;
}
// ============================================================================
// MFA/2FA Types
// ============================================================================
export interface TOTPSetupResponse {
secret: string;
qr_code_url: string;
backup_codes: string[];
}
export interface TOTPConfirmData {
token: string;
}
export interface TOTPVerifyData {
token: string;
}
export interface MFAChallengeData {
code: string;
}
// ============================================================================
// OAuth Types (for future implementation)
// ============================================================================
export type OAuthProvider = 'google' | 'github';
export interface OAuthCallbackData {
code: string;
state: string;
}
// ============================================================================
// Auth State Types
// ============================================================================
export interface AuthState {
user: User | null;
isAuthenticated: boolean;
isLoading: boolean;
isInitialized: boolean;
error: string | null;
}
export interface AuthContextType extends AuthState {
login: (credentials: LoginCredentials) => Promise<void>;
register: (data: RegisterData) => Promise<void>;
logout: () => Promise<void>;
refreshToken: () => Promise<void>;
updateProfile: (data: UpdateProfileData) => Promise<void>;
changePassword: (data: ChangePasswordData) => Promise<void>;
requestPasswordReset: (email: string) => Promise<void>;
checkAuth: () => Promise<void>;
}
// ============================================================================
// Token Management Types
// ============================================================================
export interface TokenPayload {
user_id: string;
email: string;
exp: number;
iat: number;
token_type: 'access' | 'refresh';
}
export interface TokenStorage {
getAccessToken: () => string | null;
setAccessToken: (token: string) => void;
getRefreshToken: () => string | null;
setRefreshToken: (token: string) => void;
clearTokens: () => void;
hasValidAccessToken: () => boolean;
}