In Angular-13, after a user successfully logs in, I have this login response:
{
"data": {
"id": "3333-3841-43d1-9bae-dddd",
"token": "anythingsdsdsdsds",
"user": {
"id": 33333-3841-43d1-9bae-ea32e1165021",
"firstName": "Janet",
"lastName": "Wilow",
"email": "[email protected]",
"userName": "JWilow"
},
"roles": [
"Teacher"
],
"expires": "2022-06-23T15:01:21.4727432 01:00",
"refreshToken": "9333333-e67e-4deb-84a6-6efdraw"
},
"successful": true,
"message": "Login Successfully",
"statusCode": 200
}
Then in Angular, I want to create a LoginResponse Interface:
login-response.ts:
export interface LoginResponse{
}
How do I represent each field in the LoginResponse Interface?
Thanks
CodePudding user response:
Use multiple interfaces to represent each object.
export interface ILoginResponse{
data: ILoginDetails
successful: boolean;
message: string;
statusCode: boolean;
}
export interface ILogin{
id: string;
token: string;
user: IUser;
roles: IRole[];
expires: Date;
refreshToken: string;
}
export interface IUser{
id: string;
firstName: string;
lastName: string;
email: string;
userName: string;
}
export interface IRole {
role: string;
}