Skip to content

Commit 31867b0

Browse files
refactor: the creadability of the code in the verification email
1 parent fe41983 commit 31867b0

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/pages/verify-email.tsx

Lines changed: 17 additions & 16 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";
@@ -26,23 +26,24 @@ export default function EmailVerification(): ReactElement {
2626
const { locale } = useRouter();
2727
const dispatch = useDispatch();
2828

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

4748
const goHome = () => {
4849
router.push("/login");

0 commit comments

Comments
 (0)