-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Handle email code verification in the app (#13)
- Loading branch information
Showing
11 changed files
with
107 additions
and
18 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
49 changes: 49 additions & 0 deletions
49
...WebAuthnUpgradeExamplePage/UpgradeExample/EmailVerificationCode/EmailVerificationCode.tsx
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,49 @@ | ||
import type { ReactNode } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { applyActionCode } from 'firebase/auth'; | ||
import { parseAsString, parseAsStringLiteral, useQueryStates } from 'nuqs'; | ||
|
||
import { QueryLoader } from '@workspace/common/client/api/components'; | ||
import { env } from '@workspace/common/client/env'; | ||
import { auth } from '@workspace/common/client/firebase/config'; | ||
|
||
import { useExampleRouter } from '../DefaultExampleRouter'; | ||
|
||
export interface EmailVerificationCodeProps { | ||
children: ReactNode; | ||
} | ||
|
||
export function EmailVerificationCode({ children }: EmailVerificationCodeProps) { | ||
const [params] = useQueryStates({ | ||
apiKey: parseAsString, | ||
mode: parseAsStringLiteral(['verifyEmail'] as const), | ||
oobCode: parseAsString, | ||
continueUrl: parseAsString, | ||
}); | ||
|
||
const { push } = useRouter(); | ||
const { redirect } = useExampleRouter(); | ||
|
||
const result = useQuery({ | ||
queryKey: ['emailVerification', params], | ||
queryFn: async () => { | ||
const { mode, oobCode, continueUrl, apiKey } = params; | ||
|
||
if (mode !== 'verifyEmail' || !oobCode || apiKey !== env.NEXT_PUBLIC_FIREBASE_API_KEY || !continueUrl) { | ||
return null; | ||
} | ||
|
||
await applyActionCode(auth(), oobCode); | ||
await auth().currentUser?.reload(); | ||
|
||
await push(continueUrl); | ||
|
||
redirect('/login-with-password'); | ||
|
||
return null; | ||
}, | ||
}); | ||
|
||
return <QueryLoader result={result}>{children}</QueryLoader>; | ||
} |
1 change: 1 addition & 0 deletions
1
...e/src/components/WebAuthnUpgradeExamplePage/UpgradeExample/EmailVerificationCode/index.ts
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 @@ | ||
export * from './EmailVerificationCode'; |
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
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