From 7ecb5b373478551014ab5f7092faafac972125cb Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 17 Feb 2021 12:06:00 +0100 Subject: [PATCH] settings flow --- packages/dashboard/src/pages/settings.js | 130 +++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 packages/dashboard/src/pages/settings.js diff --git a/packages/dashboard/src/pages/settings.js b/packages/dashboard/src/pages/settings.js new file mode 100644 index 00000000..f9b36b1d --- /dev/null +++ b/packages/dashboard/src/pages/settings.js @@ -0,0 +1,130 @@ +// import Link from "next/link"; +import { Configuration, PublicApi } from "@ory/kratos-client"; +import config from "../config"; +// import Message from "../components/Form/Message"; + +const kratos = new PublicApi(new Configuration({ basePath: config.kratos.public })); + +export async function getServerSideProps(context) { + const flow = context.query.flow; + + // 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") { + console.log("No flow ID found in URL, initializing settings flow."); + + return { + redirect: { + permanent: false, + destination: `${config.kratos.browser}/self-service/settings/browser`, + }, + }; + } + + try { + const { status, data } = await kratos.getSelfServiceSettingsFlow(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/settings/browser`, + }, + }; + } +} + +// const fieldProps = { +// email: { +// label: "Your email", +// autoComplete: "email", +// position: 0, +// }, +// csrf_token: { +// position: 99, +// }, +// }; + +export default function Settings({ flow }) { + console.log(flow); + + return null; + // const fields = flow.methods.link.config.fields + // .map((field) => ({ + // ...field, + // ...fieldProps[field.name], + // })) + // .sort((a, b) => (a.position < b.position ? -1 : 1)); + // return ( + //
+ //
+ // + // + // + //

Recover your account

+ //

+ // or{" "} + // + // sign in + // {" "} + // if you suddenly remembered your password + //

+ //
+ //
+ //
+ //
+ // {fields.map((field) => ( + //
+ // {field.type !== "hidden" && ( + // + // )} + //
+ // + //
+ // {Boolean(field.messages?.length) && ( + //
+ // text)} /> + //
+ // )} + //
+ // ))} + //
+ // + //
+ // {(flow?.messages ?? []).map((message) => ( + // + // ))} + // + //
+ //
+ //
+ // ); +}