import Link from "next/link"; import { Configuration, PublicApi } from "@ory/kratos-client"; import config from "../../config"; import SelfServiceForm from "../../components/Form/SelfServiceForm"; const kratos = new PublicApi(new Configuration({ basePath: config.kratos.public })); export async function getServerSideProps(context) { const flow = context.query.flow; const redirect = encodeURIComponent(`/api/accounts/login?return_to=${context.query.return_to ?? "/"}`); if (process.env.NODE_ENV === "development") { return { props: { flow: require("../../../stubs/login.json") } }; } // The flow is used to identify the login and registration flow and // return data like the csrf_token and so on. if (!flow || typeof flow !== "string") { // No flow ID found in URL, initializing login flow. return { redirect: { permanent: false, destination: `${config.kratos.browser}/self-service/login/browser?return_to=${redirect}`, }, }; } try { const { status, data } = await kratos.getSelfServiceLoginFlow(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/login/browser?return_to=${redirect}`, }, }; } } const fieldsConfig = { identifier: { label: "Email address", autoComplete: "email", position: 0, }, password: { label: "Password", autoComplete: "current-password", position: 1, }, csrf_token: { position: 99, }, }; export default function Login({ flow }) { return (

Sign in to your account

or{" "} sign up {" "} if you don't have one yet

Forgot your password?
); }