Skip to content

Commit

Permalink
cleanup: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Jan 14, 2025
1 parent 7c23dc9 commit 62e4f47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export const emailSchema = object({
})

export const emailTokenSchema = object({
token: string().required('required').trim().matches(/^[0-9]{6}$/, 'otp code must be 6 digits')
token: string().required('required').trim().matches(/^[0-9]{6}$/, 'must be 6 digits')
})

export const urlSchema = object({
Expand Down
15 changes: 8 additions & 7 deletions pages/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export const getServerSideProps = getGetServerSideProps({ query: null })

export default function Email () {
const router = useRouter()
const [callback, setCallback] = useState('') // TODO
const [callback, setCallback] = useState('') // callback.email, callback.callbackUrl
const [isPWA, setIsPWA] = useState(false)

const checkPWA = () => {
// TODO: evaluate independent checkPWA function
const checkPWA = () => { // from pull-to-refresh.js
const androidPWA = window.matchMedia('(display-mode: standalone)').matches
const iosPWA = window.navigator.standalone === true
setIsPWA(androidPWA || iosPWA)
Expand All @@ -25,8 +26,10 @@ export default function Email () {
setCallback(JSON.parse(window.sessionStorage.getItem('callback')))
}, [])

// build and push the final callback URL
const pushCallback = (token) => {
router.push(`/api/auth/callback/email?${callback.callbackUrl ? `callbackUrl=${callback.callbackUrl}` : ''}&token=${token}&email=${encodeURIComponent(callback.email)}`)
const url = `/api/auth/callback/email?${callback.callbackUrl ? `callbackUrl=${callback.callbackUrl}` : ''}&token=${token}&email=${encodeURIComponent(callback.email)}`
router.push(url)
}

return (
Expand All @@ -38,7 +41,7 @@ export default function Email () {
</video>
<h2 className='pt-4'>Check your email</h2>
<h4 className='text-muted pt-2 pb-4'>A {isPWA ? 'magic code' : 'sign in link'} has been sent to {callback ? callback.email : 'your email address'}</h4>
{isPWA && <MagicCodeForm onSubmit={async (token) => pushCallback(token)} />}
{isPWA && <MagicCodeForm onSubmit={(token) => pushCallback(token)} />}
</div>
</StaticLayout>
)
Expand All @@ -51,9 +54,7 @@ export const MagicCodeForm = ({ onSubmit }) => {
token: ''
}}
schema={emailTokenSchema}
onSubmit={async ({ token }) => {
await onSubmit(token)
}}
onSubmit={({ token }) => { onSubmit(token) }}
>
<PasswordInput name='token' required placeholder='input your 6-digit magic code' />
<SubmitButton variant='primary' className='px-4'>verify</SubmitButton>
Expand Down

0 comments on commit 62e4f47

Please sign in to comment.