-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement OTP verification for password reset (#517)
- Loading branch information
1 parent
79df1f8
commit 9c28eee
Showing
6 changed files
with
167 additions
and
44 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
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,137 @@ | ||
import styled from 'styled-components'; | ||
import { H3, ItalicText, Text } from '@hibiscus/ui'; | ||
import { Colors2023 } from '@hibiscus/styles'; | ||
import OTPInput from '../otp-input/otp-input'; | ||
import { useState } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { HibiscusSupabaseClient } from '@hibiscus/hibiscus-supabase-client'; | ||
import Image from 'next/image'; | ||
import { MutatingDots } from 'react-loader-spinner'; | ||
import { Button } from '@hibiscus/ui-kit-2023'; | ||
import { useHibiscusSupabase } from '@hibiscus/hibiscus-supabase-context'; | ||
|
||
export function ResetVerifyCard() { | ||
const router = useRouter(); | ||
const { supabase } = useHibiscusSupabase(); | ||
const [verifyState, setVerifyState] = useState(''); | ||
const [hideErrorMessage, setHideErrorMessage] = useState(false); | ||
const [code, setCode] = useState(''); | ||
const [pinReady, setPinReady] = useState(false); | ||
const MAX_CODE_LENGTH = 6; | ||
|
||
const handleOTP = async () => { | ||
const email = String(router.query.email); | ||
|
||
const { data, error } = await supabase.verifyOtp(email, code, 'recovery'); | ||
|
||
if (error) { | ||
console.log(error); | ||
setHideErrorMessage(true); | ||
} | ||
if (data.user) { | ||
setVerifyState('verifying'); | ||
|
||
HibiscusSupabaseClient.setTokenCookieClientSide( | ||
data.session.access_token, | ||
data.session.refresh_token | ||
); | ||
|
||
router.push('/reset'); | ||
} | ||
}; | ||
|
||
const handleKeyDown = (e) => { | ||
//it triggers by pressing the enter key | ||
console.log(e.target.value); | ||
if (e.keyCode === 13) { | ||
handleOTP(); | ||
} | ||
}; | ||
|
||
return ( | ||
<StyledVerifyCard> | ||
<Image | ||
src="/static/images/logo-2023.svg" | ||
alt="HackSC Logo" | ||
width={100} | ||
height={100} | ||
/> | ||
<StyledText> | ||
We've sent you an email containing a unique 6-digit PIN code. | ||
</StyledText> | ||
<ItalicText> | ||
This email may take up to 2 minutes to arrive. Do not share this code | ||
with anyone else. | ||
</ItalicText> | ||
<OTPInput | ||
setPinReady={setPinReady} | ||
code={code} | ||
setCode={setCode} | ||
maxLength={MAX_CODE_LENGTH} | ||
handleKeyDown={handleKeyDown} | ||
/> | ||
<StyledErrorText style={{ display: hideErrorMessage ? 'block' : 'none' }}> | ||
Token is expired or incorrect. | ||
</StyledErrorText> | ||
<Button | ||
color="blue" | ||
onClick={handleOTP} | ||
disabled={!pinReady} | ||
style={{ | ||
opacity: !pinReady ? 0.5 : 1, | ||
cursor: 'pointer', | ||
transitionDuration: '0.5s', | ||
}} | ||
> | ||
SUBMIT | ||
</Button> | ||
|
||
<Text>If you did not receive your email, please sign up again</Text> | ||
|
||
{verifyState === 'verifying' ? ( | ||
<MutatingDots | ||
height="100" | ||
width="100" | ||
color={Colors2023.BLUE.LIGHT} | ||
secondaryColor={Colors2023.BLUE.LIGHT} | ||
radius="12.5" | ||
ariaLabel="mutating-dots-loading" | ||
/> | ||
) : ( | ||
'' | ||
)} | ||
</StyledVerifyCard> | ||
); | ||
} | ||
|
||
export default ResetVerifyCard; | ||
|
||
const StyledVerifyCard = styled.div` | ||
min-width: 55vw; | ||
max-width: 90vw; | ||
padding: 5rem 2rem; | ||
display: flex; | ||
flex-direction: column; | ||
margin: auto; | ||
align-items: center; | ||
border-radius: 20px; | ||
border: 5px solid ${Colors2023.BLUE.STANDARD}; | ||
box-shadow: 0px 0px 10px ${Colors2023.BLUE.LIGHT}; | ||
gap: 15px; | ||
> p { | ||
text-align: center; | ||
} | ||
@media (max-width: 400px) { | ||
padding: 2rem; | ||
} | ||
`; | ||
|
||
const StyledText = styled(H3)` | ||
text-align: center; | ||
`; | ||
|
||
const StyledErrorText = styled(Text)` | ||
font-size: 20px; | ||
padding-top: 1rem; | ||
color: red; | ||
`; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import styled from 'styled-components'; | ||
import Head from 'next/head'; | ||
import { getWebTitle } from '@hibiscus/metadata'; | ||
import ResetVerifyCard from '../../components/verify-card/reset-verify-card'; | ||
|
||
export function Index() { | ||
return ( | ||
<MainPageWrapper> | ||
<Head> | ||
<title>{getWebTitle('Reset your password')}</title> | ||
</Head> | ||
|
||
<ResetVerifyCard /> | ||
</MainPageWrapper> | ||
); | ||
} | ||
export default Index; | ||
|
||
const MainPageWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
min-height: 100vh; | ||
`; |
9c28eee
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.
Successfully deployed to the following URLs:
pointr – ./
pointr.vercel.app
www.hack.sc
pointr-git-main-hacksc.vercel.app
pointr-hacksc.vercel.app
9c28eee
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.
Successfully deployed to the following URLs:
interim – ./
interim-hacksc.vercel.app
interim-git-main-hacksc.vercel.app
www.socalhacks.org
socalhacks.org
9c28eee
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.
Successfully deployed to the following URLs:
dashboard – ./
dashboard-git-main-hacksc.vercel.app
dashboard.hacksc.com
dashboard-sable-sigma.vercel.app
dashboard-hacksc.vercel.app
9c28eee
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.
Successfully deployed to the following URLs:
recruitment – ./
recruitment-git-main-hacksc.vercel.app
recruitment-hacksc.vercel.app
9c28eee
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.
Successfully deployed to the following URLs:
www-2023 – ./
www-2023-hacksc.vercel.app
2023.hacksc.com
www-2023-git-main-hacksc.vercel.app
www-2023.vercel.app
9c28eee
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.
Successfully deployed to the following URLs:
sso – ./
sso-steel.vercel.app
sso-hacksc.vercel.app
sso-git-main-hacksc.vercel.app
sso.hacksc.com
9c28eee
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.
Successfully deployed to the following URLs:
ui-kit-2023-storybook – ./
ui-kit-2023-storybook.vercel.app
ui-kit-2023-storybook-git-main-hacksc.vercel.app
ui-kit-2023-storybook-hacksc.vercel.app
storybook.hacksc.com