otp: register the token after success login
This commit is contained in:
@@ -3,15 +3,17 @@ import OtpIcon from "components/Icons/otpIcon.tsx";
|
||||
import OtpInput from "components/OtpInput/OtpInput";
|
||||
import ProText from "components/ProText";
|
||||
import ProTitle from "components/ProTitle";
|
||||
import { loginSuccess } from "features/auth/authSlice";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useConfirmOtpMutation, useSendOtpMutation } from "redux/api/auth";
|
||||
import { useAppDispatch } from "redux/hooks";
|
||||
import { ProGray1 } from "ThemeConstants";
|
||||
import { ACCESS_TOKEN } from "utils/constants";
|
||||
|
||||
export default function OtpPage() {
|
||||
const { subdomain } = useParams();
|
||||
const dispatch = useAppDispatch();
|
||||
const { t } = useTranslation();
|
||||
const [sendOtp, { isLoading }] = useSendOtpMutation();
|
||||
const [confirmOtp, { isLoading: isConfirmLoading }] = useConfirmOtpMutation();
|
||||
@@ -81,11 +83,7 @@ export default function OtpPage() {
|
||||
confirmOtp({ otp: otp, phone: localStorage.getItem("userPhone") })
|
||||
.unwrap()
|
||||
.then((response) => {
|
||||
localStorage.setItem(
|
||||
"customer",
|
||||
JSON.stringify(response.result.customer),
|
||||
);
|
||||
localStorage.setItem(ACCESS_TOKEN, response.result.access_token);
|
||||
dispatch(loginSuccess(response));
|
||||
message.info(t("otp.confirmOTPSuccess"));
|
||||
navigate(`/${subdomain}/menu`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user