'use client'; import React, { 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'; import { AxiosError } from 'axios'; import { useRouter, useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import Image from 'next/image'; export default function Verification() { const [flow, setFlow] = useState(); const router = useRouter(); const params = useSearchParams(); 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 handleError = useCallback((error: AxiosError) => { const handle = HandleError(getFlow, setFlow, '/flow/verification', true, router); return handle(error); }, [getFlow]); const createFlow = useCallback((returnTo: string | undefined) => { kratos .createBrowserVerificationFlow({ returnTo }) .then(({ data }) => { setFlow(data); router.push(`?flow=${data.id}`); }) .catch(handleError); }, [handleError]); const updateFlow = async (body: UpdateVerificationFlowBody) => { kratos .updateVerificationFlow({ flow: String(flow?.id), updateVerificationFlowBody: body, }) .then(({ data }) => { setFlow(data); }) .catch(handleError); }; useEffect(() => { if (flow) { return; } if (flowId) { getFlow(flowId); return; } createFlow(returnTo); }, [flowId, router, returnTo, flow]); return ( Markus Thielker Intranet Verify your account {flow?.ui.messages?.map(it => { return {it.text}; })} { flow ? :
}
{ flow ? : }
); }