84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import BaseApiService from "@Front/Api/BaseApiService";
|
|
import { ICustomerTokens } from "../Id360/Customers/Customers";
|
|
import { TotpCodesReasons } from "le-coffre-resources/dist/Customer/TotpCodes";
|
|
|
|
export type IMailVerifyParams = {
|
|
email: string;
|
|
};
|
|
|
|
export type IMailVerifyReturn = {
|
|
partialPhoneNumber: string;
|
|
};
|
|
|
|
export type IVerifyTotpCodeParams = {
|
|
totpCode: string;
|
|
email: string;
|
|
};
|
|
|
|
export type IVerifyTotpCodeReturn = {
|
|
validCode: boolean;
|
|
reason: TotpCodesReasons;
|
|
};
|
|
|
|
export type ISetPasswordParams = {
|
|
password: string;
|
|
email: string;
|
|
totpCode: string;
|
|
};
|
|
|
|
export type ILoginParams = {
|
|
password: string;
|
|
email: string;
|
|
totpCode: string;
|
|
};
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
public async setPassword(body: ISetPasswordParams): Promise<ICustomerTokens> {
|
|
const url = new URL(this.baseURl.concat("/set-password"));
|
|
try {
|
|
return this.postRequest<ICustomerTokens>(url, body);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async login(body: ILoginParams): Promise<ICustomerTokens> {
|
|
const url = new URL(this.baseURl.concat("/login"));
|
|
try {
|
|
return this.postRequest<ICustomerTokens>(url, body);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
}
|