add: bring back previously disabled api calls
This commit is contained in:
+82
-73
@@ -10,12 +10,12 @@ import { AUTH_PAGE_ELEMENT, AUTH_STEP } from '@/enums';
|
||||
import { useCountdown } from '@/hooks/useCountdown';
|
||||
import StepNewPassword from '@/features/auth/components/StepNewPassword';
|
||||
import AuthFormWrapper from '@/features/auth/components/AuthFormWrapper';
|
||||
// import { useLogin } from '@/hooks/auth/useLogin';
|
||||
// import { useSignup } from '@/hooks/auth/useSignup';
|
||||
// import { useCheckUserExistsLazy } from '@/hooks/auth/useCheckUserExists';
|
||||
// import { useOtpRequest } from '@/hooks/auth/useOtpRequest';
|
||||
// import { useOtpValidation } from '@/hooks/auth/useOtpValidation';
|
||||
// import { useResetPassword } from '@/hooks/auth/useResetPassword';
|
||||
import { useLogin } from '@/hooks/auth/useLogin';
|
||||
import { useSignup } from '@/hooks/auth/useSignup';
|
||||
import { useCheckUserExistsLazy } from '@/hooks/auth/useCheckUserExists';
|
||||
import { useOtpRequest } from '@/hooks/auth/useOtpRequest';
|
||||
import { useOtpValidation } from '@/hooks/auth/useOtpValidation';
|
||||
import { useResetPassword } from '@/hooks/auth/useResetPassword';
|
||||
|
||||
type Props = object
|
||||
|
||||
@@ -32,12 +32,12 @@ function AuthIndex({ }: Props) {
|
||||
const { timerRunning, secondsLeft, restart, stop } = useCountdown(step === AUTH_STEP.ENTER_OTP);
|
||||
|
||||
const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
|
||||
// const loginMutation = useLogin()
|
||||
// const signupMutation = useSignup()
|
||||
// const { run: runUserExistCheck } = useCheckUserExistsLazy()
|
||||
// const { run: runOtpRequest } = useOtpRequest();
|
||||
// const { run: runOtpValidation } = useOtpValidation();
|
||||
// const { run: runResetPassword } = useResetPassword();
|
||||
const loginMutation = useLogin()
|
||||
const signupMutation = useSignup()
|
||||
const { run: runUserExistCheck } = useCheckUserExistsLazy()
|
||||
const { run: runOtpRequest } = useOtpRequest();
|
||||
const { run: runOtpValidation } = useOtpValidation();
|
||||
const { run: runResetPassword } = useResetPassword();
|
||||
|
||||
const resetStates = () => {
|
||||
setNumber('');
|
||||
@@ -59,7 +59,7 @@ function AuthIndex({ }: Props) {
|
||||
useEffect(() => {
|
||||
if (step === AUTH_STEP.ENTER_OTP) {
|
||||
console.log("REQUEST OTP")
|
||||
// runOtpRequest(number);
|
||||
runOtpRequest(number);
|
||||
}
|
||||
}, [step]);
|
||||
|
||||
@@ -81,7 +81,7 @@ function AuthIndex({ }: Props) {
|
||||
const prev = otp.padEnd(6).split('');
|
||||
prev[index] = e.target.value;
|
||||
const next = prev.join('');
|
||||
if(otp.length >= 6 && next.trim().length >= otp.length) return;
|
||||
if (otp.length >= 6 && next.trim().length >= otp.length) return;
|
||||
setOtp(next.trimEnd());
|
||||
}
|
||||
}
|
||||
@@ -97,82 +97,91 @@ function AuthIndex({ }: Props) {
|
||||
setShowPasswordRepeat((state) => !state);
|
||||
}
|
||||
else if (target.id === AUTH_PAGE_ELEMENT.RESET_PASSWORD) {
|
||||
setShowPassword(false);
|
||||
setShowPasswordRepeat(false);
|
||||
setPassword('');
|
||||
setPasswordRepeat('');
|
||||
setStep(() => AUTH_STEP.ENTER_OTP)
|
||||
}
|
||||
else if (target.id === AUTH_PAGE_ELEMENT.RESEND_OTP) {
|
||||
if (!timerRunning) {
|
||||
try {
|
||||
// await runOtpRequest(number);
|
||||
await runOtpRequest(number);
|
||||
restart();
|
||||
} catch {
|
||||
|
||||
console.error("Could not ask for otp")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||
console.log(step);
|
||||
e.preventDefault();
|
||||
setIsPending(true);
|
||||
if (step == AUTH_STEP.ENTER_NUMBER) {
|
||||
try {
|
||||
setIsPending(true);
|
||||
if (step == AUTH_STEP.ENTER_NUMBER) {
|
||||
|
||||
if (true) {
|
||||
setStep(AUTH_STEP.ENTER_PASSWORD)
|
||||
} else {
|
||||
setStep(AUTH_STEP.ENTER_OTP);
|
||||
if (await runUserExistCheck(number)) {
|
||||
setStep(AUTH_STEP.ENTER_PASSWORD)
|
||||
} else {
|
||||
setStep(AUTH_STEP.ENTER_OTP);
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_PASSWORD) {
|
||||
try {
|
||||
await loginMutation.mutateAsync({ phone: number, password })
|
||||
console.log("Logged in")
|
||||
redirect("/")
|
||||
}
|
||||
catch (e) {
|
||||
console.error("Wrong credentials: ", e)
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_OTP) {
|
||||
if (!await runOtpValidation({ phone: number, otp })) {
|
||||
setOtp('');
|
||||
console.error('Wrong otp');
|
||||
}
|
||||
stop();
|
||||
console.log(await runUserExistCheck(number));
|
||||
if (await runUserExistCheck(number)) {
|
||||
console.log("1")
|
||||
setStep(AUTH_STEP.ENTER_RESET_PASSWORD)
|
||||
} else {
|
||||
console.log("2")
|
||||
setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_RESET_PASSWORD) {
|
||||
console.log("Password changed")
|
||||
try {
|
||||
await runResetPassword({
|
||||
phone: number,
|
||||
newPassword: password,
|
||||
otp
|
||||
})
|
||||
resetStates();
|
||||
setStep(AUTH_STEP.ENTER_NUMBER)
|
||||
} catch (ex) {
|
||||
console.error('Password reset failed: ', ex)
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_NEW_PASSWORD) {
|
||||
try {
|
||||
await signupMutation.mutateAsync({ phone: number, password })
|
||||
console.log("Signed up")
|
||||
redirect("/")
|
||||
}
|
||||
catch (e) {
|
||||
console.error("Could not signup: ", e)
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_PASSWORD) {
|
||||
try {
|
||||
// await loginMutation.mutateAsync({ phone: number, password })
|
||||
useAuthStore.getState().isAuthenticated = true;
|
||||
console.log("Logged in")
|
||||
redirect("/")
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Wrong credentials: ", e)
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_OTP) {
|
||||
// if (!await runOtpValidation({ phone: number, otp })) {
|
||||
// setOtp('');
|
||||
// console.log('Wrong otp');
|
||||
// }
|
||||
setOtp('');
|
||||
stop();
|
||||
// if (await runUserExistCheck(number)) {
|
||||
// setStep(AUTH_STEP.ENTER_RESET_PASSWORD)
|
||||
// } else {
|
||||
// setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
|
||||
// }
|
||||
setStep(AUTH_STEP.ENTER_NEW_PASSWORD)
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_RESET_PASSWORD) {
|
||||
console.log("Password changed")
|
||||
try {
|
||||
// await runResetPassword({
|
||||
// phone: number,
|
||||
// newPassword: password,
|
||||
// otp
|
||||
// })
|
||||
resetStates();
|
||||
setStep(AUTH_STEP.ENTER_NUMBER)
|
||||
} catch (ex) {
|
||||
console.error('Password reset failed: ', ex)
|
||||
}
|
||||
}
|
||||
else if (step == AUTH_STEP.ENTER_NEW_PASSWORD) {
|
||||
try {
|
||||
// await signupMutation.mutateAsync({ phone: number, password })
|
||||
useAuthStore.getState().isAuthenticated = true;
|
||||
console.log("Signed up")
|
||||
redirect("/")
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Could not signup: ", e)
|
||||
}
|
||||
}
|
||||
setIsPending(false);
|
||||
}
|
||||
|
||||
const stepMap = {
|
||||
|
||||
@@ -10,7 +10,7 @@ function AuthFormWrapper({ children, isPending, ...restProps }: Props) {
|
||||
<form {...restProps} className='p-6 lg:py-[75px] w-full flex items-center justify-center py-4 lg:items-center lg:px-10 px-4 drop-shadow-black h-full'>
|
||||
<div className='relative h-full w-full px-4 sm:px-6 lg:p-0 flex flex-col max-h-[812px] max-w-[1200px] bg-container rounded-container overflow-clip lg:flex-row justify-between'>
|
||||
{children}
|
||||
<LoadingOverlay visible={isPending} />
|
||||
<LoadingOverlay visible={isPending} bgOpacity={0} />
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user