✨ Login working
This commit is contained in:
parent
485b63d5ed
commit
3315bd53bd
@ -25,6 +25,12 @@ export type ISetPasswordParams = {
|
|||||||
totpCode: string;
|
totpCode: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ILoginParams = {
|
||||||
|
password: string;
|
||||||
|
email: string;
|
||||||
|
totpCode: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default class Auth extends BaseApiService {
|
export default class Auth extends BaseApiService {
|
||||||
private static instance: Auth;
|
private static instance: Auth;
|
||||||
protected readonly namespaceUrl = this.getBaseUrl().concat("/customer");
|
protected readonly namespaceUrl = this.getBaseUrl().concat("/customer");
|
||||||
@ -63,4 +69,14 @@ export default class Auth extends BaseApiService {
|
|||||||
return Promise.reject(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ export default function Login() {
|
|||||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
try {
|
try {
|
||||||
if (!values["email"]) return;
|
if (!values["email"]) return;
|
||||||
|
setEmail(values["email"]);
|
||||||
const res = await Auth.getInstance().mailVerifySms({ email: values["email"] });
|
const res = await Auth.getInstance().mailVerifySms({ email: values["email"] });
|
||||||
setPartialPhoneNumber(res.partialPhoneNumber);
|
setPartialPhoneNumber(res.partialPhoneNumber);
|
||||||
setEmail(values["email"]);
|
|
||||||
setStep(LoginStep.TOTP);
|
setStep(LoginStep.TOTP);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// If token already exists and is still valid redirect to the connect/register page
|
// If token already exists and is still valid redirect to the connect/register page
|
||||||
@ -133,16 +133,16 @@ export default function Login() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[email, totpCode, setValidationErrors],
|
[totpCode, email, router],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onPasswordSubmit = useCallback(
|
const onPasswordSubmit = useCallback(
|
||||||
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
try {
|
try {
|
||||||
if (!values["password"]) return;
|
if (!values["password"]) return;
|
||||||
const res = await Auth.getInstance().setPassword({ totpCode, email, password: values["password"] });
|
const token = await Auth.getInstance().login({ totpCode, email, password: values["password"] });
|
||||||
|
CustomerStore.instance.connect(token.accessToken, token.refreshToken);
|
||||||
// If set password worked, setting the token and redirecting
|
router.push(Module.getInstance().get().modules.pages.Folder.pages.Select.props.path);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
setValidationErrors([
|
setValidationErrors([
|
||||||
{
|
{
|
||||||
@ -155,7 +155,7 @@ export default function Login() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[email, totpCode],
|
[email, router, totpCode],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user