-
Notifications
You must be signed in to change notification settings - Fork 359
Add Forgot Password link on Sign In page #1370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pratyushjha06
wants to merge
5
commits into
Code-A2Z:main
Choose a base branch
from
pratyushjha06:add-forgot-password-link
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b96edc3
Add Forgot Password link on Sign In page
pratyushjha06 9f6fb4d
Update reset password text as requested in review
pratyushjha06 d916335
Use state management instead of FormData for email input
pratyushjha06 14f94ef
Export ResetPasswordLazyComponent from components/index.tsx
pratyushjha06 813d7f6
feat: implement forgot password functionality with email integration
pratyushjha06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,197 @@ | ||
| // client/src/modules/auth/v1/reset-password/index.tsx | ||
|
|
||
| import { Box, styled, Typography } from '@mui/material'; | ||
| import InputBox from '../../../../shared/components/atoms/input-box'; | ||
| import EmailIcon from '@mui/icons-material/Email'; | ||
| import A2ZButton from '../../../../shared/components/atoms/button'; | ||
| import { useState } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import A2ZTypography from '../../../../shared/components/atoms/typography'; | ||
|
|
||
| const StyledSection = styled('section')(({ theme }) => ({ | ||
| paddingTop: theme.spacing(4), | ||
| paddingBottom: theme.spacing(4), | ||
| paddingLeft: '5vw', | ||
| paddingRight: '5vw', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| minHeight: '100vh', | ||
| })); | ||
|
|
||
| const StyledForm = styled('form')(() => ({ | ||
| width: '80%', | ||
| maxWidth: 400, | ||
| })); | ||
|
|
||
| const StyledTitle = styled(Typography)(({ theme }) => ({ | ||
| fontSize: '2.5rem', | ||
| fontFamily: 'Gelasio, serif', | ||
| textTransform: 'capitalize', | ||
| textAlign: 'center', | ||
| marginBottom: theme.spacing(6), | ||
| })); | ||
|
|
||
| const StyledFooter = styled('p')(({ theme }) => ({ | ||
| marginTop: theme.spacing(6), | ||
| color: theme.palette.text.secondary, | ||
| fontSize: '1.125rem', | ||
| textAlign: 'center', | ||
| })); | ||
|
|
||
| const ResetPassword = () => { | ||
| const [email, setEmail] = useState(''); | ||
| const [loading, setLoading] = useState(false); | ||
| const [error, setError] = useState(''); | ||
| const [success, setSuccess] = useState(false); | ||
| const navigate = useNavigate(); | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
| e.preventDefault(); | ||
| setLoading(true); | ||
| setError(''); | ||
| setSuccess(false); | ||
|
|
||
| try { | ||
| const response = await fetch('http://localhost:8000/api/auth/forgot-password', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ email }), | ||
| }); | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| if (response.ok) { | ||
| setSuccess(true); | ||
| setEmail(''); // Clear email after success | ||
| } else { | ||
| setError(data.message || 'Failed to send reset link. Please try again.'); | ||
| } | ||
| } catch (err) { | ||
| setError('Something went wrong. Please try again later.'); | ||
| console.error('Error:', err); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setEmail(e.target.value); | ||
| setError(''); // Clear error when user types | ||
| setSuccess(false); // Clear success when user types | ||
| }; | ||
|
|
||
| return ( | ||
| <StyledSection> | ||
| <StyledForm onSubmit={handleSubmit}> | ||
| <StyledTitle>Reset Password</StyledTitle> | ||
|
|
||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| gap: 1, | ||
| }} | ||
| > | ||
| <Typography | ||
| sx={{ | ||
| mb: 2, | ||
| textAlign: 'center', | ||
| color: 'text.secondary', | ||
| }} | ||
| > | ||
| Enter your email address to receive a link to reset your password. | ||
| </Typography> | ||
|
|
||
| {success && ( | ||
| <Typography | ||
| sx={{ | ||
| color: 'success.main', | ||
| fontSize: '0.9rem', | ||
| mb: 1, | ||
| width: '100%', | ||
| textAlign: 'center', | ||
| backgroundColor: 'success.light', | ||
| padding: '8px 12px', | ||
| borderRadius: '4px', | ||
| }} | ||
| > | ||
| Password reset link sent successfully! Check your email. | ||
| </Typography> | ||
| )} | ||
|
|
||
| {error && ( | ||
| <Typography | ||
| sx={{ | ||
| color: 'error.main', | ||
| fontSize: '0.9rem', | ||
| mb: 1, | ||
| width: '100%', | ||
| textAlign: 'center', | ||
| backgroundColor: 'error.light', | ||
| padding: '8px 12px', | ||
| borderRadius: '4px', | ||
| }} | ||
| > | ||
| {error} | ||
| </Typography> | ||
| )} | ||
|
|
||
| <InputBox | ||
| id="reset-email" | ||
| name="email" | ||
| type="email" | ||
| placeholder="Email" | ||
| fullWidth | ||
| icon={<EmailIcon />} | ||
| slotProps={{ | ||
| input: { | ||
| value: email, | ||
| onChange: handleEmailChange, | ||
| }, | ||
| }} | ||
| /> | ||
|
|
||
| <A2ZButton | ||
| type="submit" | ||
| sx={{ | ||
| mt: 2, | ||
| width: '100%', | ||
| }} | ||
| loading={loading} | ||
| disabled={!email || loading} | ||
| > | ||
| Send Reset Link | ||
| </A2ZButton> | ||
| </Box> | ||
|
|
||
| <StyledFooter> | ||
| Remember your password?{' '} | ||
| <A2ZTypography | ||
| text="Sign in here" | ||
| component="span" | ||
| props={{ | ||
| onClick: () => navigate('/'), | ||
| sx: { | ||
| fontSize: '1.125rem', | ||
| marginLeft: 1, | ||
| textDecoration: 'underline', | ||
| color: 'inherit', | ||
| cursor: 'pointer', | ||
| '&:hover': { | ||
| opacity: 0.8, | ||
| }, | ||
| }, | ||
| }} | ||
| /> | ||
| </StyledFooter> | ||
| </StyledForm> | ||
| </StyledSection> | ||
| ); | ||
| }; | ||
|
|
||
| export default ResetPassword; | ||
This file contains hidden or 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 hidden or 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,3 @@ | ||
| "" | ||
| "# Environment variables" | ||
| ".env" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write the api call inside
/infra/restfolder - according toauthdirectory.Before writing, please take a look on implementation / use case of api call function.