Skip to content

Commit b867fa0

Browse files
authored
Merge pull request #923 from dacadeorg/fix/verification-workflow
fix: disable double verification workflow
2 parents 0d6c166 + 31867b0 commit b867fa0

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/contexts/AuthObserver.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ export default function AuthObserver({ children }: { children: ReactNode }) {
4343

4444
const emailVerificationChecker: (auth: User | null) => Promise<void> = useCallback(
4545
async (auth: User | null) => {
46-
if (route.startsWith("/verify-email") && auth?.emailVerified) {
47-
await router.push("/");
48-
return;
49-
}
46+
if (route.startsWith("/verify-email")) return;
5047

5148
if (route.startsWith("/email-verification") && !auth) {
5249
await router.push("/");

src/pages/verify-email.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, ReactElement } from "react";
1+
import { useState, useEffect, ReactElement, useCallback } from "react";
22
import { useTranslation } from "next-i18next";
33
import Loader from "@/components/ui/Loader";
44
import ArrowButton from "@/components/ui/button/Arrow";
@@ -10,6 +10,7 @@ import Head from "next/head";
1010
import { useRouter } from "next/router";
1111
import { verifyEmail } from "@/store/services/auth.service";
1212
import { useDispatch } from "@/hooks/useTypedDispatch";
13+
import { auth } from "@/config/firebase";
1314

1415
/**
1516
* Email verification page
@@ -20,24 +21,29 @@ import { useDispatch } from "@/hooks/useTypedDispatch";
2021
*/
2122
export default function EmailVerification(): ReactElement {
2223
const { t } = useTranslation();
23-
const [verified, setVerified] = useState(true);
24+
const [verified, setVerified] = useState(false);
2425
const router = useRouter();
2526
const { locale } = useRouter();
2627
const dispatch = useDispatch();
2728

29+
const verify = useCallback(async () => {
30+
const code = router.query.code as string;
31+
if (!code) {
32+
router.push("/404");
33+
return;
34+
}
35+
try {
36+
await dispatch(verifyEmail({ locale: locale as string, payload: { code } }));
37+
await auth.currentUser?.reload();
38+
setVerified(true);
39+
} catch (error) {
40+
console.error(error);
41+
}
42+
}, []);
43+
2844
useEffect(() => {
29-
const verify = async () => {
30-
const code = router.query.code as string;
31-
if (!code) return;
32-
try {
33-
await dispatch(verifyEmail({ locale: locale as string, payload: { code } }));
34-
setVerified(true);
35-
} catch (error) {
36-
console.error(error);
37-
}
38-
};
3945
verify();
40-
}, [dispatch, locale, router.query.code]);
46+
}, [verify]);
4147

4248
const goHome = () => {
4349
router.push("/login");

0 commit comments

Comments
 (0)