2023-11-27 10:02:43 +01:00

49 lines
1.2 KiB
TypeScript

import BaseApiService from "@Front/Api/BaseApiService";
export type IMailVerifyParams = {
email: string;
};
export type IMailVerifyReturn = {
partialPhoneNumber: string;
};
export type IVerifyTotpCodeParams = {
totpCode: string;
email: string;
};
export type IVerifyTotpCodeReturn = {
validCode: boolean;
};
export default class Auth extends BaseApiService {
private static instance: Auth;
protected readonly namespaceUrl = this.getBaseUrl().concat("/customer");
private readonly baseURl = this.namespaceUrl.concat("/auth");
public static getInstance() {
return (this.instance ??= new this());
}
public async mailVerifySms(body: IMailVerifyParams): Promise<IMailVerifyReturn> {
const url = new URL(this.baseURl.concat("/mail/verify-sms"));
try {
return this.postRequest<IMailVerifyReturn>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
public async verifyTotpCode(body: IVerifyTotpCodeParams): Promise<IVerifyTotpCodeReturn> {
const url = new URL(this.baseURl.concat("/verify-totp-code"));
try {
return this.postRequest<IVerifyTotpCodeReturn>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
}