From 83f9445762f9a754340bfee0ab6c33ec97a138bb Mon Sep 17 00:00:00 2001 From: peintnermax Date: Mon, 29 Apr 2024 15:26:08 +0200 Subject: [PATCH] resp on setup --- .../app/(login)/otp/[method]/set/page.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/login/app/(login)/otp/[method]/set/page.tsx b/apps/login/app/(login)/otp/[method]/set/page.tsx index d6af424bfe4..e6f823a1c4e 100644 --- a/apps/login/app/(login)/otp/[method]/set/page.tsx +++ b/apps/login/app/(login)/otp/[method]/set/page.tsx @@ -11,6 +11,8 @@ import DynamicTheme from "#/ui/DynamicTheme"; import TOTPRegister from "#/ui/TOTPRegister"; import UserAvatar from "#/ui/UserAvatar"; import { getMostRecentCookieWithLoginname } from "#/utils/cookies"; +import { RegisterTOTPResponse } from "@zitadel/server"; +import { ClientError } from "nice-grpc"; export default async function Page({ searchParams, @@ -25,11 +27,20 @@ export default async function Page({ const branding = await getBrandingSettings(server, organization); const { session, token } = await loadSession(loginName, organization); - let totpResponse; + let totpResponse: RegisterTOTPResponse | undefined, + totpError: ClientError | undefined; if (session && session.factors?.user?.id) { if (method === "time-based") { // inconsistency with token: email works with machine token, totp works with session token - totpResponse = await registerTOTP(session.factors.user.id, token); + await registerTOTP(session.factors.user.id, token) + .then((resp) => { + if (resp) { + totpResponse = resp; + } + }) + .catch((error) => { + totpError = error; + }); } else if (method === "sms") { // does not work await addOTPSMS(session.factors.user.id); @@ -67,6 +78,12 @@ export default async function Page({ )} + {totpError && ( +
+ {totpError?.details} +
+ )} + {session && (