From 92e9150405a3602e80e8d1d24f58aedc9f6ee192 Mon Sep 17 00:00:00 2001 From: peintnermax Date: Tue, 7 May 2024 14:04:58 +0200 Subject: [PATCH] add resend capblty for sms, email otp --- apps/login/ui/Alert.tsx | 2 +- apps/login/ui/LoginOTP.tsx | 37 +++++++++++++++++++++++--- apps/login/utils/session.ts | 52 ++++++++++++++++--------------------- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/apps/login/ui/Alert.tsx b/apps/login/ui/Alert.tsx index c5bf05ea8f2..4c246c0369b 100644 --- a/apps/login/ui/Alert.tsx +++ b/apps/login/ui/Alert.tsx @@ -38,7 +38,7 @@ export default function Alert({ children, type = AlertType.ALERT }: Props) { {type === AlertType.INFO && ( )} - {children} + {children} ); } diff --git a/apps/login/ui/LoginOTP.tsx b/apps/login/ui/LoginOTP.tsx index d046c8ebc2c..ab396509242 100644 --- a/apps/login/ui/LoginOTP.tsx +++ b/apps/login/ui/LoginOTP.tsx @@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "react"; import { useRouter } from "next/navigation"; import { coerceToArrayBuffer, coerceToBase64Url } from "#/utils/base64"; import { Button, ButtonVariants } from "./Button"; -import Alert from "./Alert"; +import Alert, { AlertType } from "./Alert"; import { Spinner } from "./Spinner"; import { Checks } from "@zitadel/server"; import { useForm } from "react-hook-form"; @@ -140,8 +140,10 @@ export default function LoginOTP({ if (!res.ok) { const response = await res.json(); - setError(response.message ?? "An internal error occurred"); - return Promise.reject(response.message ?? "An internal error occurred"); + setError(response.details.details ?? "An internal error occurred"); + return Promise.reject( + response.details.details ?? "An internal error occurred" + ); } return res.json(); } @@ -184,7 +186,34 @@ export default function LoginOTP({ return (
-
+ {["email", "sms"].includes(method) && ( + +
+ + Did not get the Code? + + +
+
+ )} +
setTimeout(resolve, 1000)).then(() => - // TODO: remove - getSession(server, sessionCookie.id, sessionCookie.token).then( - (response) => { - if ( - response?.session && - response.session.factors?.user?.loginName - ) { - const { session } = response; - const newCookie: SessionCookie = { - id: sessionCookie.id, - token: updatedSession.sessionToken, - creationDate: sessionCookie.creationDate, - expirationDate: sessionCookie.expirationDate, - changeDate: `${session.changeDate?.getTime() ?? ""}`, - loginName: session.factors?.user?.loginName ?? "", - organization: session.factors?.user?.organizationId ?? "", - }; + return getSession(server, sessionCookie.id, sessionCookie.token).then( + (response) => { + if (response?.session && response.session.factors?.user?.loginName) { + const { session } = response; + const newCookie: SessionCookie = { + id: sessionCookie.id, + token: updatedSession.sessionToken, + creationDate: sessionCookie.creationDate, + expirationDate: sessionCookie.expirationDate, + changeDate: `${session.changeDate?.getTime() ?? ""}`, + loginName: session.factors?.user?.loginName ?? "", + organization: session.factors?.user?.organizationId ?? "", + }; - if (sessionCookie.authRequestId) { - newCookie.authRequestId = sessionCookie.authRequestId; - } - - return updateSessionCookie(sessionCookie.id, newCookie).then( - () => { - return { challenges: updatedSession.challenges, ...session }; - } - ); - } else { - throw "could not get session or session does not have loginName"; + if (sessionCookie.authRequestId) { + newCookie.authRequestId = sessionCookie.authRequestId; } + + return updateSessionCookie(sessionCookie.id, newCookie).then(() => { + return { challenges: updatedSession.challenges, ...session }; + }); + } else { + throw "could not get session or session does not have loginName"; } - ) + } ); } else { throw "Session not be set";