diff --git a/apps/login/src/ui/ChooseSecondFactorToSetup.tsx b/apps/login/src/ui/ChooseSecondFactorToSetup.tsx
index 94315a40e68..eb1b47806ee 100644
--- a/apps/login/src/ui/ChooseSecondFactorToSetup.tsx
+++ b/apps/login/src/ui/ChooseSecondFactorToSetup.tsx
@@ -1,6 +1,9 @@
"use client";
-import { LoginSettings } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
+import {
+ LoginSettings,
+ SecondFactorType,
+} from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
import { EMAIL, SMS, TOTP, U2F } from "./AuthMethods";
@@ -47,28 +50,37 @@ export default function ChooseSecondFactorToSetup({
return (
- {loginSettings.secondFactors.map((factor, i) => {
- return factor === 1
- ? TOTP(
+ {loginSettings.secondFactors.map((factor) => {
+ switch (factor) {
+ case SecondFactorType.OTP:
+ return TOTP(
userMethods.includes(AuthenticationMethodType.TOTP),
"/otp/time-based/set?" + params,
- )
- : factor === 2
- ? U2F(
- userMethods.includes(AuthenticationMethodType.U2F),
- "/u2f/set?" + params,
+ );
+ case SecondFactorType.U2F:
+ return U2F(
+ userMethods.includes(AuthenticationMethodType.U2F),
+ "/u2f/set?" + params,
+ );
+ case SecondFactorType.OTP_EMAIL:
+ return (
+ emailVerified &&
+ EMAIL(
+ userMethods.includes(AuthenticationMethodType.OTP_EMAIL),
+ "/otp/email/set?" + params,
)
- : factor === 3 && emailVerified
- ? EMAIL(
- userMethods.includes(AuthenticationMethodType.OTP_EMAIL),
- "/otp/email/set?" + params,
- )
- : factor === 4 && phoneVerified
- ? SMS(
- userMethods.includes(AuthenticationMethodType.OTP_SMS),
- "/otp/sms/set?" + params,
- )
- : null;
+ );
+ case SecondFactorType.OTP_SMS:
+ return (
+ phoneVerified &&
+ SMS(
+ userMethods.includes(AuthenticationMethodType.OTP_SMS),
+ "/otp/sms/set?" + params,
+ )
+ );
+ default:
+ return null;
+ }
})}
);
diff --git a/apps/login/src/ui/LoginPasskey.tsx b/apps/login/src/ui/LoginPasskey.tsx
index 448d0a8220a..00dc283ae43 100644
--- a/apps/login/src/ui/LoginPasskey.tsx
+++ b/apps/login/src/ui/LoginPasskey.tsx
@@ -50,19 +50,20 @@ export default function LoginPasskey({
const pK =
response?.challenges?.webAuthN?.publicKeyCredentialRequestOptions
?.publicKey;
- if (pK) {
- submitLoginAndContinue(pK)
- .then(() => {
- setLoading(false);
- })
- .catch((error) => {
- setError(error);
- setLoading(false);
- });
- } else {
+
+ if (!pK) {
setError("Could not request passkey challenge");
setLoading(false);
}
+
+ return submitLoginAndContinue(pK)
+ .then(() => {
+ setLoading(false);
+ })
+ .catch((error) => {
+ setError(error);
+ setLoading(false);
+ });
})
.catch((error) => {
setError(error);
@@ -135,59 +136,57 @@ export default function LoginPasskey({
publicKey,
})
.then((assertedCredential: any) => {
- if (assertedCredential) {
- const authData = new Uint8Array(
- assertedCredential.response.authenticatorData,
- );
- const clientDataJSON = new Uint8Array(
- assertedCredential.response.clientDataJSON,
- );
- const rawId = new Uint8Array(assertedCredential.rawId);
- const sig = new Uint8Array(assertedCredential.response.signature);
- const userHandle = new Uint8Array(
- assertedCredential.response.userHandle,
- );
- const data = {
- id: assertedCredential.id,
- rawId: coerceToBase64Url(rawId, "rawId"),
- type: assertedCredential.type,
- response: {
- authenticatorData: coerceToBase64Url(authData, "authData"),
- clientDataJSON: coerceToBase64Url(
- clientDataJSON,
- "clientDataJSON",
- ),
- signature: coerceToBase64Url(sig, "sig"),
- userHandle: coerceToBase64Url(userHandle, "userHandle"),
- },
- };
- return submitLogin(data).then((resp) => {
- if (authRequestId && resp && resp.sessionId) {
- return router.push(
- `/login?` +
- new URLSearchParams({
- sessionId: resp.sessionId,
- authRequest: authRequestId,
- }),
- );
- } else {
- const params = new URLSearchParams({});
-
- if (authRequestId) {
- params.set("authRequestId", authRequestId);
- }
- if (resp?.factors?.user?.loginName) {
- params.set("loginName", resp.factors.user.loginName);
- }
-
- return router.push(`/signedin?` + params);
- }
- });
- } else {
+ if (!assertedCredential) {
setLoading(false);
setError("An error on retrieving passkey");
- return null;
+ return;
}
+
+ const authData = new Uint8Array(
+ assertedCredential.response.authenticatorData,
+ );
+ const clientDataJSON = new Uint8Array(
+ assertedCredential.response.clientDataJSON,
+ );
+ const rawId = new Uint8Array(assertedCredential.rawId);
+ const sig = new Uint8Array(assertedCredential.response.signature);
+ const userHandle = new Uint8Array(
+ assertedCredential.response.userHandle,
+ );
+ const data = {
+ id: assertedCredential.id,
+ rawId: coerceToBase64Url(rawId, "rawId"),
+ type: assertedCredential.type,
+ response: {
+ authenticatorData: coerceToBase64Url(authData, "authData"),
+ clientDataJSON: coerceToBase64Url(clientDataJSON, "clientDataJSON"),
+ signature: coerceToBase64Url(sig, "sig"),
+ userHandle: coerceToBase64Url(userHandle, "userHandle"),
+ },
+ };
+
+ return submitLogin(data).then((resp) => {
+ if (authRequestId && resp && resp.sessionId) {
+ return router.push(
+ `/login?` +
+ new URLSearchParams({
+ sessionId: resp.sessionId,
+ authRequest: authRequestId,
+ }),
+ );
+ } else {
+ const params = new URLSearchParams({});
+
+ if (authRequestId) {
+ params.set("authRequestId", authRequestId);
+ }
+ if (resp?.factors?.user?.loginName) {
+ params.set("loginName", resp.factors.user.loginName);
+ }
+
+ return router.push(`/signedin?` + params);
+ }
+ });
})
.catch((error) => {
console.error(error);
@@ -245,7 +244,27 @@ export default function LoginPasskey({
className="self-end"
variant={ButtonVariants.Primary}
disabled={loading}
- onClick={() => updateSessionForChallenge()}
+ onClick={async () => {
+ const response = await updateSessionForChallenge();
+
+ const pK =
+ response?.challenges?.webAuthN?.publicKeyCredentialRequestOptions
+ ?.publicKey;
+
+ if (!pK) {
+ setError("Could not request passkey challenge");
+ setLoading(false);
+ }
+
+ return submitLoginAndContinue(pK)
+ .then(() => {
+ setLoading(false);
+ })
+ .catch((error) => {
+ setError(error);
+ setLoading(false);
+ });
+ }}
>
{loading && }
continue