verify code/otp
This commit is contained in:
@@ -132,7 +132,7 @@ function AuthProvider({ children }: AuthProviderProps) {
|
|||||||
|
|
||||||
const validateOtp = async (phoneOrEmail: string, otp: string) =>
|
const validateOtp = async (phoneOrEmail: string, otp: string) =>
|
||||||
axios
|
axios
|
||||||
.post('/verify-code', { otp })
|
.post('/verify-code', { phoneOrEmail: phoneOrEmail, otp })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const { user, token } = response.data.data;
|
const { user, token } = response.data.data;
|
||||||
setSession(token);
|
setSession(token);
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ export default function Login() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if (state !== null) {
|
if (state !== null) {
|
||||||
// setFormPhone(state.formPhone);
|
setFormPhone(state.formPhone);
|
||||||
// }
|
}
|
||||||
// console.log(state);
|
console.log(state);
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link as RouterLink, useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
// @mui
|
// @mui
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import { Box, Card, Divider, IconButton, Grid, Link, Stack, Typography } from '@mui/material';
|
import { Box, Card, Divider, IconButton, Grid, Link, Stack, Typography } from '@mui/material';
|
||||||
@@ -50,7 +50,7 @@ export default function VerifyCode() {
|
|||||||
<Grid item xs={6}>
|
<Grid item xs={6}>
|
||||||
<Image visibleByDefault disabledEffect src="/images/login-image.gif" alt="login" />
|
<Image visibleByDefault disabledEffect src="/images/login-image.gif" alt="login" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={6} sx={{ padding: 3 }}>
|
<Grid item xs={6} sx={{ padding: 3, textAlign: 'center' }}>
|
||||||
<Stack direction="column" sx={{ mb: 5 }}>
|
<Stack direction="column" sx={{ mb: 5 }}>
|
||||||
<Stack direction="row" alignItems="center">
|
<Stack direction="row" alignItems="center">
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -68,36 +68,35 @@ export default function VerifyCode() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box sx={{ flexGrow: 1 }}>
|
<Box sx={{ flexGrow: 1 }}>
|
||||||
<Typography variant="body1" sx={{ color: 'text.secondary' }}>
|
<Typography variant="body1" sx={{ color: 'text.secondary', textAlign: 'left' }}>
|
||||||
Masukkan kode OTP anda disini
|
Masukkan kode OTP anda disini
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<VerifyCodeForm />
|
<VerifyCodeForm phoneOrEmail={state.phoneOrEmail} />
|
||||||
|
|
||||||
|
<Typography sx={{ marginTop: 5 }}>Tidak mendapatkan kode?</Typography>
|
||||||
|
<Link sx={{ marginTop: 1 }}>Kirim Ulang Kode OTP</Link>
|
||||||
|
|
||||||
<Divider sx={{ marginTop: 5 }}>Atau</Divider>
|
<Divider sx={{ marginTop: 5 }}>Atau</Divider>
|
||||||
|
|
||||||
<Stack sx={{ marginTop: 5 }}>
|
<Stack sx={{ marginTop: 5 }}>
|
||||||
{state.formPhone === false ? (
|
{state.formPhone ? (
|
||||||
<Link
|
<Link
|
||||||
align="center"
|
align="center"
|
||||||
underline="hover"
|
underline="hover"
|
||||||
onClick={() =>
|
onClick={() => navigate('/auth/login', { state: { formPhone: false } })}
|
||||||
navigate('/auth/login', { state: { formPhone: state.formPhone } })
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
Masuk menggunakan nomor handphone
|
Masuk menggunakan email
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
align="center"
|
align="center"
|
||||||
underline="hover"
|
underline="hover"
|
||||||
onClick={() =>
|
onClick={() => navigate('/auth/login', { state: { formPhone: true } })}
|
||||||
navigate('/auth/login', { state: { formPhone: state.formPhone } })
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
Masuk menggunakan email
|
Masuk menggunakan nomor handphone
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useForm, Controller } from 'react-hook-form';
|
|||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from '@hookform/resolvers/yup';
|
||||||
// @mui
|
// @mui
|
||||||
import { OutlinedInput, Stack } from '@mui/material';
|
import { OutlinedInput, Stack } from '@mui/material';
|
||||||
import { LoadingButton } from '@mui/lab';
|
|
||||||
import useAuth from '../../../hooks/useAuth';
|
import useAuth from '../../../hooks/useAuth';
|
||||||
// routes
|
// routes
|
||||||
// import { PATH_DASHBOARD } from '../../../routes/paths';
|
// import { PATH_DASHBOARD } from '../../../routes/paths';
|
||||||
@@ -21,9 +20,13 @@ type FormValuesProps = {
|
|||||||
code4: string;
|
code4: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
phoneOrEmail: string;
|
||||||
|
};
|
||||||
|
|
||||||
type ValueNames = 'code1' | 'code2' | 'code3' | 'code4';
|
type ValueNames = 'code1' | 'code2' | 'code3' | 'code4';
|
||||||
|
|
||||||
export default function VerifyCodeForm({ phoneOrEmail }: any) {
|
export default function VerifyCodeForm({ phoneOrEmail }: Props) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { validateOtp } = useAuth();
|
const { validateOtp } = useAuth();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user