feat: standardize login response format with code, message, and data wrapper
Update login endpoint to return consistent API response structure with code, message, and data fields. Wrap token, refreshToken, and user data inside a data object to match the standardized response format used across other endpoints.
This commit is contained in:
parent
4ff57555a2
commit
d7f824f353
3 changed files with 42 additions and 30 deletions
|
|
@ -28,31 +28,35 @@ export class AuthController {
|
|||
@SuccessResponse('200', 'Login successful')
|
||||
@Response('401', 'Invalid credentials')
|
||||
@Example<LoginResponse>({
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
email: 'admin@elearning.local',
|
||||
updated_at: new Date('2024-01-01T00:00:00Z'),
|
||||
created_at: new Date('2024-01-01T00:00:00Z'),
|
||||
role: {
|
||||
code: 'ADMIN',
|
||||
name: {
|
||||
th: 'ผู้ดูแลระบบ',
|
||||
en: 'Administrator'
|
||||
}
|
||||
},
|
||||
profile: {
|
||||
prefix: {
|
||||
th: 'นาย',
|
||||
en: 'Mr.'
|
||||
code: 200,
|
||||
message: 'Login successful',
|
||||
data: {
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
refreshToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
email: 'admin@elearning.local',
|
||||
updated_at: new Date('2024-01-01T00:00:00Z'),
|
||||
created_at: new Date('2024-01-01T00:00:00Z'),
|
||||
role: {
|
||||
code: 'ADMIN',
|
||||
name: {
|
||||
th: 'ผู้ดูแลระบบ',
|
||||
en: 'Administrator'
|
||||
}
|
||||
},
|
||||
first_name: 'Admin',
|
||||
last_name: 'User',
|
||||
phone: null,
|
||||
avatar_url: null,
|
||||
birth_date: null
|
||||
profile: {
|
||||
prefix: {
|
||||
th: 'นาย',
|
||||
en: 'Mr.'
|
||||
},
|
||||
first_name: 'Admin',
|
||||
last_name: 'User',
|
||||
phone: null,
|
||||
avatar_url: null,
|
||||
birth_date: null
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -58,9 +58,13 @@ export class AuthService {
|
|||
logger.info('User logged in successfully', { userId: user.id, email: user.email });
|
||||
|
||||
return {
|
||||
token,
|
||||
refreshToken,
|
||||
user: await this.formatUserResponse(user)
|
||||
code: 200,
|
||||
message: 'Login successful',
|
||||
data: {
|
||||
token,
|
||||
refreshToken,
|
||||
user: await this.formatUserResponse(user)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,13 @@ export interface RegisterRequest {
|
|||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
user: UserResponse;
|
||||
code: number;
|
||||
message: string;
|
||||
data: {
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
user: UserResponse;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RegisterResponse {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue