diff --git a/apps/login/app/(login)/otp/[method]/set/page.tsx b/apps/login/app/(login)/otp/[method]/set/page.tsx index 22a134a24b4..3500182088c 100644 --- a/apps/login/app/(login)/otp/[method]/set/page.tsx +++ b/apps/login/app/(login)/otp/[method]/set/page.tsx @@ -26,10 +26,13 @@ export default async function Page({ ({ session, token }) => { if (session && session.factors?.user?.id) { if (method === "time-based") { + // inconsistency with token: email works with machine token, totp works with session token return registerTOTP(session.factors.user.id, token); } else if (method === "sms") { + // does not work return addOTPSMS(session.factors.user.id); } else if (method === "email") { + // works return addOTPEmail(session.factors.user.id); } else { throw new Error("Invalid method"); @@ -54,16 +57,15 @@ export default async function Page({ return (
-

Register TOTP

-

- Scan the QR Code or navigate to the URL manually. -

+

Register 2-factor

+ {totpResponse && "uri" in totpResponse && "secret" in totpResponse ? ( + <> +

+ Scan the QR Code or navigate to the URL manually. +

+
+ {/* {auth &&
{auth.to}
} */} -
- {/* {auth &&
{auth.to}
} */} - {totpResponse && - "uri" in totpResponse && - "secret" in totpResponse && ( - )} -
+
{" "} + + ) : ( +

+ {method === "email" + ? "Code via email was successfully added." + : method === "sms" + ? "Code via SMS was successfully added." + : ""} +

+ )}
); diff --git a/apps/login/lib/zitadel.ts b/apps/login/lib/zitadel.ts index 91df8a81413..59f7d29ce4a 100644 --- a/apps/login/lib/zitadel.ts +++ b/apps/login/lib/zitadel.ts @@ -112,9 +112,22 @@ export async function addOTPEmail( } export async function addOTPSMS( - userId: string + userId: string, + token?: string ): Promise { - const userService = user.getUser(server); + let userService; + if (token) { + const authConfig: ZitadelServerOptions = { + name: "zitadel login", + apiUrl: process.env.ZITADEL_API_URL ?? "", + token: token, + }; + + const sessionUser = initializeServer(authConfig); + userService = user.getUser(sessionUser); + } else { + userService = user.getUser(server); + } return userService.addOTPSMS({ userId }, {}); }