diff --git a/authentication/src/app/flow/verification/page.tsx b/authentication/src/app/flow/verification/page.tsx
index 365413e..51c0a6d 100644
--- a/authentication/src/app/flow/verification/page.tsx
+++ b/authentication/src/app/flow/verification/page.tsx
@@ -1,6 +1,6 @@
'use client';
-import React, { useCallback, useEffect, useState } from 'react';
+import React, {Suspense, useCallback, useEffect, useState} from 'react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Flow, HandleError, kratos } from '@/ory';
import { UpdateVerificationFlowBody, VerificationFlow } from '@ory/client';
@@ -11,8 +11,14 @@ import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import Image from 'next/image';
-export default function Verification() {
-
+export default function VerificationPage() {
+ return (
+
+
+
+ )
+}
+function Verification() {
const [flow, setFlow] = useState();
const router = useRouter();
@@ -21,24 +27,26 @@ export default function Verification() {
const flowId = params.get('flow') ?? undefined;
const returnTo = params.get('return_to') ?? undefined;
- const getFlow = useCallback((flowId: string) => {
- return kratos
- .getVerificationFlow({ id: String(flowId) })
- .then(({ data }) => setFlow(data))
- .catch((err: AxiosError) => {
- switch (err.response?.status) {
- case 410:
- case 403:
- return router.push('/flow/verification');
- }
- throw err;
- });
- }, []);
+ const getFlow = useCallback(async (flowId: string) => {
+ try {
+ const { data } = await kratos.getVerificationFlow({ id: String(flowId) });
+ setFlow(data);
+ } catch (err) {
+ const error = err as AxiosError;
+ switch (error.response?.status) {
+ case 410:
+ case 403:
+ return router.push('/flow/verification');
+ }
+ throw error;
+ }
+ }, [router]);
+
const handleError = useCallback((error: AxiosError) => {
const handle = HandleError(getFlow, setFlow, '/flow/verification', true, router);
return handle(error);
- }, [getFlow]);
+ }, [getFlow, router]);
const createFlow = useCallback((returnTo: string | undefined) => {
kratos
@@ -48,7 +56,7 @@ export default function Verification() {
router.push(`?flow=${data.id}`);
})
.catch(handleError);
- }, [handleError]);
+ }, [handleError, router]);
const updateFlow = async (body: UpdateVerificationFlowBody) => {
kratos
@@ -63,66 +71,75 @@ export default function Verification() {
};
useEffect(() => {
+ const fetchFlow = async () => {
+ if (flow) {
+ return;
+ }
- if (flow) {
- return;
- }
+ try {
+ if (flowId) {
+ await getFlow(flowId);
+ return;
+ }
- if (flowId) {
- getFlow(flowId);
- return;
- }
+ createFlow(returnTo);
+ } catch (err) {
+ console.error("Failed to fetch or create flow:", err);
+ }
+ };
+
+ fetchFlow().catch((err) =>
+ console.error("Error in fetchFlow effect:", err)
+ );
+ }, [flowId, router, returnTo, flow, createFlow, getFlow]);
- createFlow(returnTo);
- }, [flowId, router, returnTo, flow]);
return (
-
+
-
- Verify your account
-
+ Verify your account
- {flow?.ui.messages?.map(it => {
- return {it.text};
- })}
+ {flow?.ui.messages?.map((it) => (
+ {it.text}
+ ))}
- {
- flow ?
-
- :
-
-
-
-
-
-
+ {flow ? (
+
+ ) : (
+
+ )}
- {
- flow ?
-
- :
-
- }
+ {flow ? (
+
+ ) : (
+
+ )}
);
}