|
|
|
@ -8,7 +8,6 @@ import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
Checkbox,
|
|
|
|
|
Divider,
|
|
|
|
|
FormControl,
|
|
|
|
|
FormControlLabel,
|
|
|
|
|
FormHelperText,
|
|
|
|
@ -18,8 +17,7 @@ import {
|
|
|
|
|
InputLabel,
|
|
|
|
|
OutlinedInput,
|
|
|
|
|
Stack,
|
|
|
|
|
Typography,
|
|
|
|
|
useMediaQuery
|
|
|
|
|
Typography
|
|
|
|
|
} from '@mui/material';
|
|
|
|
|
|
|
|
|
|
// third party
|
|
|
|
@ -27,7 +25,6 @@ import * as Yup from 'yup';
|
|
|
|
|
import { Formik } from 'formik';
|
|
|
|
|
|
|
|
|
|
// project imports
|
|
|
|
|
import useConfig from 'hooks/useConfig';
|
|
|
|
|
import useAuth from 'hooks/useAuth';
|
|
|
|
|
import useScriptRef from 'hooks/useScriptRef';
|
|
|
|
|
import AnimateButton from 'ui-component/extended/AnimateButton';
|
|
|
|
@ -36,26 +33,14 @@ import AnimateButton from 'ui-component/extended/AnimateButton';
|
|
|
|
|
import Visibility from '@mui/icons-material/Visibility';
|
|
|
|
|
import VisibilityOff from '@mui/icons-material/VisibilityOff';
|
|
|
|
|
|
|
|
|
|
import Google from 'assets/images/icons/social-google.svg';
|
|
|
|
|
|
|
|
|
|
// ============================|| FIREBASE - LOGIN ||============================ //
|
|
|
|
|
|
|
|
|
|
const FirebaseLogin = ({ loginProp, ...others }) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const { login } = useAuth();
|
|
|
|
|
const scriptedRef = useScriptRef();
|
|
|
|
|
const matchDownSM = useMediaQuery(theme.breakpoints.down('md'));
|
|
|
|
|
const { borderRadius } = useConfig();
|
|
|
|
|
const [checked, setChecked] = React.useState(true);
|
|
|
|
|
|
|
|
|
|
const { firebaseEmailPasswordSignIn, firebaseGoogleSignIn } = useAuth();
|
|
|
|
|
const googleHandler = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await firebaseGoogleSignIn();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
|
|
|
const handleClickShowPassword = () => {
|
|
|
|
|
setShowPassword(!showPassword);
|
|
|
|
@ -68,58 +53,6 @@ const FirebaseLogin = ({ loginProp, ...others }) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Grid container direction="column" justifyContent="center" spacing={2}>
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<AnimateButton>
|
|
|
|
|
<Button
|
|
|
|
|
disableElevation
|
|
|
|
|
fullWidth
|
|
|
|
|
onClick={googleHandler}
|
|
|
|
|
size="large"
|
|
|
|
|
variant="outlined"
|
|
|
|
|
sx={{
|
|
|
|
|
color: 'grey.700',
|
|
|
|
|
backgroundColor: theme.palette.mode === 'dark' ? theme.palette.dark.main : theme.palette.grey[50],
|
|
|
|
|
borderColor: theme.palette.mode === 'dark' ? theme.palette.dark.light + 20 : theme.palette.grey[100]
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box sx={{ mr: { xs: 1, sm: 2, width: 20 } }}>
|
|
|
|
|
<img src={Google} alt="google" width={16} height={16} style={{ marginRight: matchDownSM ? 8 : 16 }} />
|
|
|
|
|
</Box>
|
|
|
|
|
Sign in with Google
|
|
|
|
|
</Button>
|
|
|
|
|
</AnimateButton>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
display: 'flex'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Divider sx={{ flexGrow: 1 }} orientation="horizontal" />
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
variant="outlined"
|
|
|
|
|
sx={{
|
|
|
|
|
cursor: 'unset',
|
|
|
|
|
m: 2,
|
|
|
|
|
py: 0.5,
|
|
|
|
|
px: 7,
|
|
|
|
|
borderColor:
|
|
|
|
|
theme.palette.mode === 'dark' ? `${theme.palette.dark.light + 20} !important` : `${theme.palette.grey[100]} !important`,
|
|
|
|
|
color: `${theme.palette.grey[900]} !important`,
|
|
|
|
|
fontWeight: 500,
|
|
|
|
|
borderRadius: `${borderRadius}px`
|
|
|
|
|
}}
|
|
|
|
|
disableRipple
|
|
|
|
|
disabled
|
|
|
|
|
>
|
|
|
|
|
OR
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<Divider sx={{ flexGrow: 1 }} orientation="horizontal" />
|
|
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid item xs={12} container alignItems="center" justifyContent="center">
|
|
|
|
|
<Box sx={{ mb: 2 }}>
|
|
|
|
|
<Typography variant="subtitle1">Sign in with Email address</Typography>
|
|
|
|
@ -129,31 +62,17 @@ const FirebaseLogin = ({ loginProp, ...others }) => {
|
|
|
|
|
|
|
|
|
|
<Formik
|
|
|
|
|
initialValues={{
|
|
|
|
|
email: 'info@codedthemes.com',
|
|
|
|
|
password: '123456',
|
|
|
|
|
userid: 'xitdev',
|
|
|
|
|
passwd: 'xitdev',
|
|
|
|
|
submit: null
|
|
|
|
|
}}
|
|
|
|
|
validationSchema={Yup.object().shape({
|
|
|
|
|
email: Yup.string().email('Must be a valid email').max(255).required('Email is required'),
|
|
|
|
|
password: Yup.string().max(255).required('Password is required')
|
|
|
|
|
userid: Yup.string().max(255).required('User ID is required'),
|
|
|
|
|
passwd: Yup.string().max(255).required('Password is required')
|
|
|
|
|
})}
|
|
|
|
|
onSubmit={async (values, { setErrors, setStatus, setSubmitting }) => {
|
|
|
|
|
try {
|
|
|
|
|
await firebaseEmailPasswordSignIn(values.email, values.password).then(
|
|
|
|
|
() => {
|
|
|
|
|
// WARNING: do not set any formik state here as formik might be already destroyed here. You may get following error by doing so.
|
|
|
|
|
// Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application.
|
|
|
|
|
// To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
|
|
|
|
|
// github issue: https://github.com/formium/formik/issues/2430
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
if (scriptedRef.current) {
|
|
|
|
|
setStatus({ success: false });
|
|
|
|
|
setErrors({ submit: err.message });
|
|
|
|
|
setSubmitting(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
await login(values.userid, values.passwd);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
if (scriptedRef.current) {
|
|
|
|
@ -166,32 +85,32 @@ const FirebaseLogin = ({ loginProp, ...others }) => {
|
|
|
|
|
>
|
|
|
|
|
{({ errors, handleBlur, handleChange, handleSubmit, isSubmitting, touched, values }) => (
|
|
|
|
|
<form noValidate onSubmit={handleSubmit} {...others}>
|
|
|
|
|
<FormControl fullWidth error={Boolean(touched.email && errors.email)} sx={{ ...theme.typography.customInput }}>
|
|
|
|
|
<InputLabel htmlFor="outlined-adornment-email-login">Email Address / Username</InputLabel>
|
|
|
|
|
<FormControl fullWidth error={Boolean(touched.userid && errors.userid)} sx={{ ...theme.typography.customInput }}>
|
|
|
|
|
<InputLabel htmlFor="userid">User ID</InputLabel>
|
|
|
|
|
<OutlinedInput
|
|
|
|
|
id="outlined-adornment-email-login"
|
|
|
|
|
type="email"
|
|
|
|
|
value={values.email}
|
|
|
|
|
name="email"
|
|
|
|
|
id="userid"
|
|
|
|
|
type="text"
|
|
|
|
|
value={values.userid}
|
|
|
|
|
name="userid"
|
|
|
|
|
onBlur={handleBlur}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
label="Email Address / Username"
|
|
|
|
|
label="User ID"
|
|
|
|
|
inputProps={{}}
|
|
|
|
|
/>
|
|
|
|
|
{touched.email && errors.email && (
|
|
|
|
|
<FormHelperText error id="standard-weight-helper-text-email-login">
|
|
|
|
|
{errors.email}
|
|
|
|
|
{touched.userid && errors.userid && (
|
|
|
|
|
<FormHelperText error id="standard-weight-helper-text-userid-login">
|
|
|
|
|
{errors.userid}
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
)}
|
|
|
|
|
</FormControl>
|
|
|
|
|
|
|
|
|
|
<FormControl fullWidth error={Boolean(touched.password && errors.password)} sx={{ ...theme.typography.customInput }}>
|
|
|
|
|
<InputLabel htmlFor="outlined-adornment-password-login">Password</InputLabel>
|
|
|
|
|
<FormControl fullWidth error={Boolean(touched.passwd && errors.passwd)} sx={{ ...theme.typography.customInput }}>
|
|
|
|
|
<InputLabel htmlFor="passwd">Password</InputLabel>
|
|
|
|
|
<OutlinedInput
|
|
|
|
|
id="outlined-adornment-password-login"
|
|
|
|
|
id="passwd"
|
|
|
|
|
type={showPassword ? 'text' : 'password'}
|
|
|
|
|
value={values.password}
|
|
|
|
|
name="password"
|
|
|
|
|
value={values.passwd}
|
|
|
|
|
name="passwd"
|
|
|
|
|
onBlur={handleBlur}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
endAdornment={
|
|
|
|
@ -210,9 +129,9 @@ const FirebaseLogin = ({ loginProp, ...others }) => {
|
|
|
|
|
label="Password"
|
|
|
|
|
inputProps={{}}
|
|
|
|
|
/>
|
|
|
|
|
{touched.password && errors.password && (
|
|
|
|
|
{touched.passwd && errors.passwd && (
|
|
|
|
|
<FormHelperText error id="standard-weight-helper-text-password-login">
|
|
|
|
|
{errors.password}
|
|
|
|
|
{errors.passwd}
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
)}
|
|
|
|
|
</FormControl>
|
|
|
|
|