✨ Login & set password not returns a valid JWT
This commit is contained in:
parent
65d6e548d1
commit
624dc26dca
@ -22,7 +22,7 @@ export default class AuthController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
let customer = await this.customerService.getOne({
|
||||
const customer = await this.customerService.getOne({
|
||||
where: {
|
||||
contact: {
|
||||
email,
|
||||
@ -41,8 +41,16 @@ export default class AuthController extends ApiController {
|
||||
// if no sms code has been generated, generate it
|
||||
// if code has expired, regenerate it
|
||||
const now = new Date().getTime();
|
||||
if (!customer.smsCodeExpire || now > customer.smsCodeExpire.getTime()) {
|
||||
customer = await this.customerService.generateSmsCode(customer);
|
||||
if (customer.smsCodeExpire && now < customer.smsCodeExpire.getTime()) {
|
||||
this.httpBadRequest(response, "Last sms code is still valid");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.customerService.generateSmsCode(customer);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
}
|
||||
|
||||
if (!customer.password) {
|
||||
@ -128,8 +136,12 @@ export default class AuthController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const customerHydrated = Customer.hydrate<Customer>(customer);
|
||||
const payload = await this.authService.getCustomerJwtPayload([customerHydrated]);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
try {
|
||||
this.httpSuccess(response, { customer: Customer.hydrate<Customer>(customer) });
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
@ -192,8 +204,12 @@ export default class AuthController extends ApiController {
|
||||
const hashedPassword = await this.authService.hashPassword(password);
|
||||
await this.customerService.setPassword(customer, hashedPassword);
|
||||
|
||||
const customerHydrated = Customer.hydrate<Customer>(customer);
|
||||
const payload = await this.authService.getCustomerJwtPayload([customerHydrated]);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
try {
|
||||
this.httpSuccess(response, { email });
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
|
Loading…
x
Reference in New Issue
Block a user