From 58169cb48481c9baf49cb770611821a0bdd34359 Mon Sep 17 00:00:00 2001 From: David Edler Date: Fri, 27 Sep 2024 15:45:44 +0200 Subject: [PATCH] fix show email in case it is a hidden field as disabled input with a change email link to restart the flow. fixes #290 Signed-off-by: David Edler --- ui/components/NodeInputHidden.tsx | 36 ++++++++++++++++++++++++++++++- ui/pages/login.tsx | 21 ++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ui/components/NodeInputHidden.tsx b/ui/components/NodeInputHidden.tsx index 946f971dd..c49864341 100644 --- a/ui/components/NodeInputHidden.tsx +++ b/ui/components/NodeInputHidden.tsx @@ -1,7 +1,41 @@ import { NodeInputProps } from "./helpers"; import React, { FC } from "react"; +import { Input } from "@canonical/react-components"; + +export const NodeInputHidden: FC = ({ + node, + attributes, + setValue, +}) => { + // todo: limit this to the email field for password input, this should not show up for mfa or other steps + if ( + node.group === "default" && + attributes.name === "identifier" && + attributes.node_type === "input" && + !attributes.disabled + ) { + return ( + + E-Mail + + Change e-mail + + + } + onChange={(e) => void setValue(e.target.value)} + disabled={true} + defaultValue={attributes.value as string} + /> + ); + } -export const NodeInputHidden: FC = ({ attributes }) => { return ( { aal, login_challenge, use_backup_code: useBackupCode, + reset_email: resetEmail, } = router.query; const redirectToErrorPage = () => { @@ -71,6 +72,24 @@ const Login: NextPage = () => { window.location.href = data.redirect_to; return; } + if (resetEmail) { + const csrfNode = data?.ui.nodes.find( + (node) => + node.group === "default" && + node.attributes.node_type === "input" && + node.attributes.name === "csrf_token", + )?.attributes as UiNodeInputAttributes; + + // todo this returns 500 and does not work + // need a way to unset the ory_kratos_session cookie, but it is httponly + void kratos.updateLoginFlow({ + flow: String(data?.id), + updateLoginFlowBody: { + method: "", + csrf_token: (csrfNode.value as string) ?? "", + } as UpdateLoginFlowBody, + }); + } setFlow(data); }) .catch(handleFlowError("login", setFlow)) @@ -103,6 +122,8 @@ const Login: NextPage = () => { return "password"; }; + console.log(values); + return kratos .updateLoginFlow({ flow: String(flow?.id),