add login checkin

This commit is contained in:
Warunee Tamkoo 2025-02-19 16:21:53 +07:00
parent 13a7ccc997
commit 4fdbc122e4

View file

@ -51,4 +51,44 @@ export class LoginController extends Controller {
return new HttpSuccess(_data);
}
}
/**
* API login checkin
*
* @summary - login checkin
*
*/
@Post("checkin")
async loginCheckin(
@Body()
body: {
username: string;
password: string;
},
) {
const data = {
client_id: "gettoken-checkin",
client_secret: process.env.KC_CHECKIN_SECRET,
grant_type: "password",
requested_token_type: "urn:ietf:params:oauth:token-type:refresh_token",
username: body.username,
password: body.password,
};
let _data: any = null;
await Promise.all([
await new CallAPI()
.PostDataKeycloak(`/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`, data)
.then(async (x) => {
_data = x;
})
.catch(async (x) => {
throw new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
}),
]);
if (_data == null) {
return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
} else {
return new HttpSuccess(_data);
}
}
}