import React from 'react'; import { useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; // material-ui import { useTheme } from '@mui/material/styles'; import { Box, Button, Checkbox, Divider, FormControl, FormControlLabel, FormHelperText, Grid, IconButton, InputAdornment, InputLabel, OutlinedInput, Stack, Typography, useMediaQuery } from '@mui/material'; // third party import * as Yup from 'yup'; import { Formik } from 'formik'; // project imports import useAuth from 'hooks/useAuth'; import useScriptRef from 'hooks/useScriptRef'; import AnimateButton from 'ui-component/extended/AnimateButton'; // assets import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; import Google from 'assets/images/icons/social-google.svg'; import { DefaultRootStateProps } from 'types'; // ============================|| FIREBASE - LOGIN ||============================ // const FirebaseLogin = (props: { loginProp?: number }, { ...others }) => { const theme = useTheme(); const scriptedRef = useScriptRef(); const matchDownSM = useMediaQuery(theme.breakpoints.down('md')); const customization = useSelector((state: DefaultRootStateProps) => state.customization); 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); }; const handleMouseDownPassword = (event: React.SyntheticEvent) => { event.preventDefault(); }; return ( <> Sign in with Email address { 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: any) => { if (scriptedRef.current) { setStatus({ success: false }); setErrors({ submit: err.message }); setSubmitting(false); } } ); } catch (err: any) { console.error(err); if (scriptedRef.current) { setStatus({ success: false }); setErrors({ submit: err.message }); setSubmitting(false); } } }} > {({ errors, handleBlur, handleChange, handleSubmit, isSubmitting, touched, values }) => (
Email Address / Username {touched.email && errors.email && ( {errors.email} )} Password {showPassword ? : } } label="Password" inputProps={{}} /> {touched.password && errors.password && ( {errors.password} )} setChecked(event.target.checked)} name="checked" color="primary" /> } label="Remember me" /> Forgot Password? {errors.submit && ( {errors.submit} )}
)}
); }; export default FirebaseLogin;