Reset password option added

This commit is contained in:
2021-10-25 13:57:25 -03:00
parent 94cd6f2263
commit cb24697838
7 changed files with 133 additions and 1 deletions

View File

@@ -131,6 +131,7 @@ const Form = () => {
<Loading />
: null
}
<AditionalText text={`Don't remember your password?`} link={'/password-recovery'}/>
<AditionalText text={'Admin place demo look'} link={'/demo-admin-place'}/>
</div>

View File

@@ -0,0 +1,26 @@
import {getAuth, sendPasswordResetEmail } from 'firebase/auth'
const ResetPasswordFirebase = async (email) => {
try {
const auth = getAuth()
const response = await sendPasswordResetEmail(auth, email)
return {
sucess: true,
message: `Recovery email send!`
}
} catch(error) {
console.log(error)
return {
sucess: false,
message: `There's been an error sending the email...`
}
}
}
export default ResetPasswordFirebase

View File

@@ -0,0 +1,78 @@
import React, {useState} from 'react'
import { withRouter } from 'react-router'
import ResetPasswordFirebase from './Firebase Querys/ResetPasswordFirebase'
import Loading from '../../../../Loading/Loading'
import Messages from '../../../../Messages/Messages'
const PasswordRecovery = (props) => {
const [email, setEmail] = useState('')
const [loading, setLoading] = useState(false)
const [data, setData] = useState(false)
const recoveryPassword = async (e) => {
setLoading(true)
setData(false)
e.preventDefault()
if (email === '') {
setData({
sucess: false,
message: `Please, give your email for reset your password`
})
setLoading(false)
return
}
const response = await ResetPasswordFirebase(email)
setData(response)
setEmail('')
setLoading(false)
}
return (
<>
{
loading ?
<Loading />
: null
}
<header>
<h1>Password Recovery</h1>
<button
className="redirect-button"
onClick={() => props.history.push('/identify')}
>
Back to identify
</button>
</header>
<div className="form-container">
{
data ?
<Messages data={data}/>
: null
}
<form
onSubmit={(e) => recoveryPassword(e)}
>
<input
type="email"
placeholder="Your email"
onChange={(e) => setEmail(e.target.value)}
value={email}
/>
<input type="submit" value="Send recovery email" />
</form>
</div>
</>
)
}
export default withRouter(PasswordRecovery)