import Link from "next/link"; import { Configuration, PublicApi } from "@ory/kratos-client"; import config from "../config"; import SelfServiceForm from "../components/Form/SelfServiceForm"; import { useEffect } from "react"; const kratos = new PublicApi(new Configuration({ basePath: config.kratos.public })); export async function getServerSideProps(context) { const flow = context.query.flow; // if (process.env.NODE_ENV === "development") { // return { props: { flow: require("../../stubs/recovery.json") } }; // } if (!flow || typeof flow !== "string") { return { redirect: { permanent: false, destination: `${config.kratos.browser}/self-service/verification/browser`, }, }; } try { const { status, data } = await kratos.getSelfServiceVerificationFlow(flow); if (status === 200) return { props: { flow: data } }; throw new Error(`Failed to retrieve flow ${flow} with code ${status}`); } catch (error) { return { redirect: { permanent: false, destination: `${config.kratos.browser}/self-service/verification/browser`, }, }; } } const fieldsConfig = { email: { label: "Your email", autoComplete: "email", position: 0, }, csrf_token: { position: 99, }, }; export default function Verify({ flow }) { const state = flow.state; useEffect(() => { if (state === "passed_challenge") { setTimeout(() => (window.location = "/"), 5000); } }, [state]); return (

{flow.state === "passed_challenge" ? "Verification successful!" : "Account verification"}

{flow.state === "passed_challenge" && ( <>

You will be redirected automatically

go to dashboard

)}
{flow.state !== "passed_challenge" && ( )}
); }