-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from amitroy-thedev/main
Setup the forgot password page
- Loading branch information
Showing
2 changed files
with
85 additions
and
1 deletion.
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,82 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { auth } from "../Firebase/firebase"; | ||
import { sendPasswordResetEmail } from "firebase/auth"; | ||
|
||
function Login() { | ||
const [email, setEmail] = useState(""); | ||
const [loading, setLoading] = useState(false); | ||
const [message, setMessage] = useState(""); | ||
const [error, setError] = useState(null); | ||
const navigate = useNavigate(); | ||
|
||
const handleResetPassword = async (e) => { | ||
e.preventDefault(); | ||
setError(null); | ||
setLoading(true); | ||
try { | ||
await sendPasswordResetEmail(auth, email); | ||
setLoading(false); | ||
setMessage("Password reset email sent! Please check your inbox."); | ||
} catch (error) { | ||
setLoading(false); | ||
setError(error.message); | ||
} | ||
}; | ||
|
||
return ( | ||
<div | ||
className="container mt-5 justify-content-center" | ||
style={{ height: "auto" }} | ||
> | ||
<div className="row justify-content-center" style={{ width: "100%" }}> | ||
<div className="col-md-6"> | ||
<div className="card shadow"> | ||
<div className="card-body"> | ||
<h2 className="text-center mb-4">Forgot Password</h2> | ||
{error && <div className="alert alert-danger">{error}</div>} | ||
{message && ( | ||
<div className="alert alert-success">{message}</div> | ||
)} | ||
<form onSubmit={handleResetPassword}> | ||
<div className="mb-3"> | ||
<label htmlFor="email" className="form-label"> | ||
Email: | ||
</label> | ||
<input | ||
type="email" | ||
id="email" | ||
className="form-control" | ||
placeholder="Enter your email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
<button | ||
type="submit" | ||
className="btn btn-primary w-100" | ||
disabled={loading} | ||
> | ||
{loading ? "Requesting..." : "Request password link"} | ||
</button> | ||
</form> | ||
<p className="mt-3 text-center"> | ||
Remember you password {" "} | ||
<span | ||
className="text-primary" | ||
style={{ cursor: "pointer" }} | ||
onClick={() => navigate("/login")} | ||
> | ||
Login | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Login; |