-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'catrawalkar-authentication' into main
- Loading branch information
Showing
16 changed files
with
883 additions
and
23,748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
REACT_APP_apiKey=apiKey | ||
REACT_APP_authDomain=authDomain | ||
REACT_APP_databaseURL=databaseURL | ||
REACT_APP_projectId=projectId | ||
REACT_APP_storageBucket=storageBucket | ||
REACT_APP_messagingSenderId=messagingSenderId | ||
REACT_APP_appId=appId | ||
REACT_APP_measurementId=measurementId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/node_modules | ||
/node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +0,0 @@ | ||
<!-- | ||
IMPORTANT: Please use the following link to create a new issue: | ||
https://www.creative-tim.com/new-issue/material-dashboard-react | ||
**If your issue was not created using the app above, it will be closed immediately.** | ||
--> | ||
|
||
<!-- | ||
Love Creative Tim? Do you need Angular, React, Vuejs or HTML? You can visit: | ||
👉 https://www.creative-tim.com/bundles | ||
👉 https://www.creative-tim.com | ||
--> | ||
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import { | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
Slide, | ||
Step, | ||
StepLabel, | ||
Stepper, | ||
TextField, | ||
Typography, | ||
} from "@material-ui/core"; | ||
|
||
import { useAuthState } from "react-firebase-hooks/auth"; | ||
|
||
import { firebase_app } from "data/firebase-config"; | ||
import { useForm, Controller } from "react-hook-form"; | ||
import MaterialUiPhoneNumber from "material-ui-phone-number"; | ||
import firebase from "firebase/app"; | ||
import { useHistory } from "react-router"; | ||
|
||
const Auth = (props) => { | ||
const [user, loading, error] = useAuthState(firebase_app.auth()); | ||
const [open, setOpen] = useState(false); | ||
const [phone, setPhone] = useState(""); | ||
const [code, setCode] = useState(""); | ||
const [showLoading, setShowLoading] = useState(false); | ||
|
||
let history = useHistory(); | ||
|
||
const [activeStep, setActiveStep] = React.useState(0); | ||
const [confirmationResultCopy, setConfirmationResultCopy] = useState(); | ||
|
||
const getStepContent = (step) => { | ||
switch (step) { | ||
case 0: | ||
return ( | ||
<MaterialUiPhoneNumber | ||
name="phone" | ||
label="Phone Number" | ||
data-cy="user-phone" | ||
defaultCountry={"in"} | ||
countryCodeEditable={false} | ||
value={phone} | ||
onChange={(value) => setPhone(value)} | ||
/> | ||
); | ||
case 1: | ||
return ( | ||
<TextField | ||
label="Enter OTP" | ||
onChange={(e) => setCode(e.target.value)} | ||
value={code} | ||
/> | ||
); | ||
case 2: | ||
return ( | ||
<TextField | ||
label="Enter Name" | ||
onChange={(e) => setCode(e.target.value)} | ||
value={code} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
!loading && setOpen(!user ? true : false); | ||
setActiveStep(0); | ||
}, [loading, user]); | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier( | ||
"sign-in-button", | ||
{ | ||
size: "invisible", | ||
callback: function (response) { | ||
// reCAPTCHA solved, allow signInWithPhoneNumber. | ||
login(); | ||
}, | ||
} | ||
); | ||
}, 100); | ||
}, []); | ||
|
||
const login = () => { | ||
setShowLoading(true); | ||
// setupRecaptcha(); | ||
const appVerifier = window.recaptchaVerifier; | ||
firebase_app | ||
.auth() | ||
.signInWithPhoneNumber(phone, appVerifier) | ||
.then((confirmationResult) => { | ||
setShowLoading(false); | ||
setActiveStep((prevActiveStep) => prevActiveStep + 1); | ||
setConfirmationResultCopy(confirmationResult); | ||
window.confirmationResult = confirmationResult; | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
const verifyOtp = () => { | ||
setShowLoading(true); | ||
|
||
confirmationResultCopy | ||
.confirm(code) | ||
.then((result) => { | ||
setShowLoading(false); | ||
setPhone(""); | ||
setCode(""); | ||
// User signed in successfully. | ||
const user = result.user; | ||
setActiveStep((prevActiveStep) => prevActiveStep + 1); | ||
|
||
// console.log("SUCCESS"); | ||
}) | ||
.catch((error) => { | ||
console.log("ERROR"); | ||
}); | ||
}; | ||
|
||
const Transition = React.forwardRef(function Transition(props, ref) { | ||
return <Slide direction="down" ref={ref} {...props} />; | ||
}); | ||
|
||
return ( | ||
<Dialog | ||
open={open} | ||
// TransitionComponent={Transition} | ||
onClose={() => { | ||
props.setShowLoginPopup && props.setShowLoginPopup(false); | ||
setOpen(false); | ||
!props.setShowLoginPopup && history.push("/dashboard"); | ||
}} | ||
keepMounted | ||
aria-labelledby="alert-dialog-slide-title" | ||
aria-describedby="alert-dialog-slide-description" | ||
> | ||
<DialogTitle id="alert-dialog-slide-title"> | ||
{"Signin to proceed"} | ||
</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id="alert-dialog-slide-description"></DialogContentText> | ||
<div>{getStepContent(activeStep)}</div> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
disabled={activeStep === 0 || showLoading} | ||
onClick={() => setActiveStep((prevActiveStep) => prevActiveStep - 1)} | ||
color="primary" | ||
> | ||
Back | ||
</Button> | ||
{activeStep === 0 ? ( | ||
<Button | ||
disabled={showLoading || phone.length < 10} | ||
onClick={login} | ||
color="primary" | ||
> | ||
Generate OTP | ||
</Button> | ||
) : ( | ||
<Button disabled={showLoading} onClick={verifyOtp} color="primary"> | ||
Verify | ||
</Button> | ||
)} | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default Auth; |
Oops, something went wrong.