-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
feat: email verification #925
Open
moshfeu
wants to merge
8
commits into
master
Choose a base branch
from
email-verification
base: master
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
8 commits
Select commit
Hold shift + click to select a range
e915dc5
feat: email verification
moshfeu 4f5240d
show modal + mask email
moshfeu 1b75348
complete verification modal
moshfeu 1e37997
handle renew-session error, re-style toast
moshfeu 5cb98f5
complete the flow & improve verification modal design
moshfeu 45bff76
prettier
moshfeu 34d942e
typo
moshfeu 5e14c29
make a bit more readable
moshfeu 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 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
File renamed without changes.
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
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
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,65 @@ | ||
import { useState } from 'react'; | ||
import styled from 'styled-components/macro'; | ||
import { useApi } from '../../../context/apiContext/ApiContext'; | ||
import { useUser } from '../../../context/userContext/UserContext'; | ||
import Button from '../../../Me/components/Button'; | ||
import { maskEmail } from '../../../utils/maskSansitiveString'; | ||
|
||
type VerificationModalProps = { | ||
onSuccess: () => void; | ||
email: string; | ||
}; | ||
|
||
const ModalText = styled.p` | ||
text-align: center; | ||
font-size: 16px; | ||
line-height: 1.5; | ||
`; | ||
|
||
export const VerificationModal = ({ onSuccess }: VerificationModalProps) => { | ||
const [loading, setLoading] = useState(false); | ||
const { emailVerifiedInfo } = useUser(); | ||
const api = useApi(); | ||
|
||
if (emailVerifiedInfo.isVerified === true) { | ||
// eslint-disable-next-line no-console | ||
console.warn('email is verified'); | ||
return; | ||
} | ||
|
||
const send = async () => { | ||
setLoading(true); | ||
try { | ||
const result = await api.resendVerificationEmail(); | ||
if (result.success) { | ||
onSuccess(); | ||
} | ||
} catch {} | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ModalText> | ||
Psst, we believe that you are who you say you are. | ||
<br /> | ||
Just to make sure, we need you to verify your email. | ||
<h3>Recognize {maskEmail(emailVerifiedInfo.email)}?</h3> | ||
{emailVerifiedInfo.isRegisteredRecently ? ( | ||
<> | ||
This is the address we sent a verification email to. | ||
<br /> | ||
Can't find it? Hit the button | ||
</> | ||
) : ( | ||
<>Hit the button to send a verification email right to your inbox</> | ||
)} | ||
<p> | ||
<Button isLoading={loading} onClick={send}> | ||
Resend verification email | ||
</Button> | ||
</p> | ||
</ModalText> | ||
</> | ||
); | ||
}; |
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
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.
Is this static method still necessary after adding
forgetUser
to the auth util?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.
Yes.
forgetUser
calls this function.The problem is that auth/utils not always has a reference to API so if it has reference it calls to
clearCurrentUser
but if not (it means that apiService is not initiated), it callsclearCurrentUserFromStorage
directly.We definitely should improve the design / structure of the auth / user area. We 2 providers and 2 services.
I did some research about auth0 react wrapper, it can help us clear our code but I didn't want to include this refactor in this PR to avoid big changes at once.
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.
5e14c29
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.
Sounds good. Thanks.