user.model.ts
angular/comprehensive-demo/src/app/models/user.model.ts
/**
* User Model
*
* This interface defines the structure of a User object in our application.
* Using TypeScript interfaces provides:
* - Type safety: Ensures data conforms to expected structure
* - IntelliSense: Better IDE support and autocomplete
* - Documentation: Serves as inline documentation for developers
* - Compile-time checks: Catches errors before runtime
*/
export interface User {
/**
* Unique identifier for the user
* Typically generated by the backend database
*/
id: number;
/**
* User's first name
*/
firstName: string;
/**
* User's last name
*/
lastName: string;
/**
* User's email address - used for authentication and communication
*/
email: string;
/**
* User's role in the system (e.g., 'admin', 'user', 'guest')
* Used for role-based access control (RBAC)
*/
role: 'admin' | 'user' | 'guest';
/**
* Whether the user account is currently active
* Inactive users may be restricted from certain actions
*/
isActive: boolean;
/**
* Timestamp when the user account was created
* ISO 8601 format string
*/
createdAt: string;
/**
* Timestamp when the user account was last updated
* ISO 8601 format string
*/
updatedAt: string;
}
/**
* User Registration Data
*
* Data structure for creating a new user account.
* Note: This doesn't include fields like 'id' or 'createdAt' which are
* generated by the backend.
*/
export interface UserRegistration {
firstName: string;
lastName: string;
email: string;
password: string;
role?: 'admin' | 'user' | 'guest'; // Optional, defaults to 'user'
}
/**
* User Login Credentials
*
* Data structure for user authentication
*/
export interface LoginCredentials {
email: string;
password: string;
}
/**
* Authentication Response
*
* Structure of the response received after successful authentication
*/
export interface AuthResponse {
/**
* JWT (JSON Web Token) used for authenticated API requests
* This token should be stored securely and included in HTTP headers
*/
token: string;
/**
* Refresh token used to obtain a new access token when it expires
* Typically has a longer expiration time than the access token
*/
refreshToken: string;
/**
* User information returned after successful authentication
*/
user: User;
/**
* Token expiration time in seconds
*/
expiresIn: number;
}
Articoli correlati
server.js
server.js — javascript source code from the angular learning materials (angular/comprehensive-demo/server/server.js).
Leggi l'articolo →app.component.ts
app.component.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.component.ts).
Leggi l'articolo →app.config.ts
app.config.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.config.ts).
Leggi l'articolo →app.routes.ts
app.routes.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/app.routes.ts).
Leggi l'articolo →auth.guard.ts
auth.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/auth.guard.ts).
Leggi l'articolo →role.guard.ts
role.guard.ts — typescript source code from the angular learning materials (angular/comprehensive-demo/src/app/core/guards/role.guard.ts).
Leggi l'articolo →