130 lines
2.8 KiB
TypeScript
130 lines
2.8 KiB
TypeScript
/**
|
|
* Auth Domain - Contract
|
|
*
|
|
* Canonical authentication types shared across applications.
|
|
*/
|
|
|
|
import type { IsoDateTimeString } from "../common/types";
|
|
import type { CustomerProfile, Address } from "../customer/contract";
|
|
import type { Activity } from "../dashboard/contract";
|
|
|
|
export type UserRole = "USER" | "ADMIN";
|
|
|
|
/**
|
|
* AuthenticatedUser - Complete user profile with authentication state
|
|
* Extends CustomerProfile (from WHMCS) with auth-specific fields from portal DB
|
|
* Follows WHMCS client field naming (firstname, lastname, etc.)
|
|
*/
|
|
export interface AuthenticatedUser extends CustomerProfile {
|
|
role: UserRole;
|
|
emailVerified: boolean;
|
|
mfaEnabled: boolean;
|
|
lastLoginAt?: IsoDateTimeString;
|
|
}
|
|
|
|
export interface AuthTokens {
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
expiresAt: IsoDateTimeString;
|
|
refreshExpiresAt: IsoDateTimeString;
|
|
tokenType: "Bearer";
|
|
}
|
|
|
|
export interface AuthResponse {
|
|
user: AuthenticatedUser;
|
|
tokens: AuthTokens;
|
|
}
|
|
|
|
export interface LoginRequest {
|
|
email: string;
|
|
password: string;
|
|
mfaCode?: string;
|
|
rememberMe?: boolean;
|
|
}
|
|
|
|
export interface SignupRequest {
|
|
email: string;
|
|
password: string;
|
|
firstname: string;
|
|
lastname: string;
|
|
phonenumber?: string;
|
|
companyname?: string;
|
|
sfNumber: string;
|
|
address?: Address;
|
|
nationality?: string;
|
|
dateOfBirth?: string;
|
|
gender?: "male" | "female" | "other";
|
|
acceptTerms: boolean;
|
|
marketingConsent?: boolean;
|
|
}
|
|
|
|
export interface ForgotPasswordRequest {
|
|
email: string;
|
|
}
|
|
|
|
export interface ResetPasswordRequest {
|
|
token: string;
|
|
password: string;
|
|
confirmPassword?: string;
|
|
}
|
|
|
|
export interface ChangePasswordRequest {
|
|
currentPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export interface LinkWhmcsRequest {
|
|
email: string;
|
|
password: string;
|
|
}
|
|
|
|
export interface SetPasswordRequest {
|
|
email: string;
|
|
password: string;
|
|
}
|
|
|
|
export interface ValidateSignupRequest {
|
|
sfNumber: string;
|
|
}
|
|
|
|
/**
|
|
* Update customer profile request (stored in WHMCS - single source of truth)
|
|
* Follows WHMCS GetClientsDetails/UpdateClient field structure
|
|
* All fields optional - only send what needs to be updated
|
|
*/
|
|
export interface UpdateCustomerProfileRequest {
|
|
// Basic profile fields
|
|
firstname?: string;
|
|
lastname?: string;
|
|
companyname?: string;
|
|
phonenumber?: string;
|
|
|
|
// Address fields (optional, can update selectively)
|
|
address1?: string;
|
|
address2?: string;
|
|
city?: string;
|
|
state?: string;
|
|
postcode?: string;
|
|
country?: string;
|
|
|
|
// Additional fields
|
|
language?: string;
|
|
}
|
|
|
|
export interface AuthError {
|
|
code:
|
|
| "INVALID_CREDENTIALS"
|
|
| "USER_NOT_FOUND"
|
|
| "EMAIL_ALREADY_EXISTS"
|
|
| "EMAIL_NOT_VERIFIED"
|
|
| "INVALID_TOKEN"
|
|
| "TOKEN_EXPIRED"
|
|
| "ACCOUNT_LOCKED"
|
|
| "RATE_LIMITED"
|
|
| "NETWORK_ERROR";
|
|
message: string;
|
|
details?: Record<string, unknown>;
|
|
}
|
|
|
|
export type { Activity };
|