From 83df5f761ee08db4e2de556b19f9d894087f0622 Mon Sep 17 00:00:00 2001 From: pnzrr Date: Thu, 29 Feb 2024 20:55:53 -0700 Subject: [PATCH 1/4] update button labels --- src/pages/profile/signin.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pages/profile/signin.tsx b/src/pages/profile/signin.tsx index 37b0ef3..3686143 100644 --- a/src/pages/profile/signin.tsx +++ b/src/pages/profile/signin.tsx @@ -19,12 +19,16 @@ import { AIACommand } from "services/aia-command"; import P2Toast from "components/utils/toast"; import { Key, Lock, Smartphone } from "lucide-react"; +const PASSWORD = "password"; +const TWO_FACTOR_AUTH = "2fa"; const WEB_AUTH_N = "webauthn"; const WEB_AUTH_N_REGISTER = "webauthn-register"; const WEB_AUTH_N_PASSWORDLESS = "webauthn-passwordless"; const WEB_AUTH_N_PASSWORDLESS_REGISTER = "webauthn-register-passwordless"; const OTP = "otp"; +type CredentialType = PASSWORD | TWO_FACTOR_AUTH | WEB_AUTH_N | OTP; + const time = (time: string | undefined): string => { if (time === undefined) return "unknown"; let t: number = Number(time); @@ -84,7 +88,7 @@ const SigninProfile = () => { ]; const rowsForType = ( - credentialType: string, + credentialType: CredentialType, credentials: CredentialRepresentation[] ): TableRows => { const metadatas: UserCredentialMetadataRepresentation[] = []; @@ -147,7 +151,7 @@ const SigninProfile = () => { /> @@ -168,7 +172,7 @@ const SigninProfile = () => { {isLoading && (
)} @@ -219,7 +223,7 @@ const SigninProfile = () => { description={t("useYourSecurityKeyToSignIn")} variant="small" /> - {rowsForType("webauthn", credentials).length !== 0 && ( + {rowsForType(WEB_AUTH_N, credentials).length !== 0 && (
From d040729a611aed3a1208527487af6106eb589f02 Mon Sep 17 00:00:00 2001 From: pnzrr Date: Mon, 4 Mar 2024 08:22:16 -0700 Subject: [PATCH 2/4] adjust typing --- src/pages/profile/signin.tsx | 76 +++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/src/pages/profile/signin.tsx b/src/pages/profile/signin.tsx index 3686143..0cc691a 100644 --- a/src/pages/profile/signin.tsx +++ b/src/pages/profile/signin.tsx @@ -19,15 +19,15 @@ import { AIACommand } from "services/aia-command"; import P2Toast from "components/utils/toast"; import { Key, Lock, Smartphone } from "lucide-react"; -const PASSWORD = "password"; -const TWO_FACTOR_AUTH = "2fa"; -const WEB_AUTH_N = "webauthn"; -const WEB_AUTH_N_REGISTER = "webauthn-register"; -const WEB_AUTH_N_PASSWORDLESS = "webauthn-passwordless"; -const WEB_AUTH_N_PASSWORDLESS_REGISTER = "webauthn-register-passwordless"; -const OTP = "otp"; - -type CredentialType = PASSWORD | TWO_FACTOR_AUTH | WEB_AUTH_N | OTP; +enum CredentialType { + PASSWORD = "password", + TWO_FACTOR_AUTH = "2fa", + WEB_AUTH_N = "webauthn", + WEB_AUTH_N_REGISTER = "webauthn-register", + WEB_AUTH_N_PASSWORDLESS = "webauthn-passwordless", + WEB_AUTH_N_PASSWORDLESS_REGISTER = "webauthn-register-passwordless", + OTP = "otp", +} const time = (time: string | undefined): string => { if (time === undefined) return "unknown"; @@ -42,11 +42,13 @@ const SigninProfile = () => { }); const [deleteCredential] = useDeleteCredentialMutation(); - const hasWebAuthN = credentials.find((cred) => cred.type === WEB_AUTH_N); + const hasWebAuthN = credentials.find( + (cred) => cred.type === CredentialType.WEB_AUTH_N + ); const hasWebAuthNPasswordLess = credentials.find( - (cred) => cred.type === WEB_AUTH_N_PASSWORDLESS + (cred) => cred.type === CredentialType.WEB_AUTH_N_PASSWORDLESS ); - const hasOTP = credentials.find((cred) => cred.type === OTP); + const hasOTP = credentials.find((cred) => cred.type === CredentialType.OTP); const removeCredential = ( credential: CredentialMetadataRepresentation @@ -109,14 +111,16 @@ const SigninProfile = () => { isCompact className="inline-flex w-full justify-center sm:ml-3 sm:w-auto" onClick={() => { - if (credentialType === "password") { + if (credentialType === CredentialType.PASSWORD) { updateAIA("UPDATE_PASSWORD"); } else { removeCredential(metadata.credential!); } }} > - {credentialType === "password" ? t("update") : t("remove")} + {credentialType === CredentialType.PASSWORD + ? t("update") + : t("remove")} )} @@ -151,7 +155,7 @@ const SigninProfile = () => { />
@@ -172,7 +176,10 @@ const SigninProfile = () => { {isLoading && (
)} @@ -188,7 +195,8 @@ const SigninProfile = () => { variant="small" /> - {rowsForType(OTP, credentials).length !== 0 && ( + {rowsForType(CredentialType.OTP, credentials).length !== + 0 && (
@@ -223,10 +231,13 @@ const SigninProfile = () => { description={t("useYourSecurityKeyToSignIn")} variant="small" /> - {rowsForType(WEB_AUTH_N, credentials).length !== 0 && ( + {rowsForType(CredentialType.WEB_AUTH_N, credentials) + .length !== 0 && ( @@ -234,13 +245,15 @@ const SigninProfile = () => {
@@ -270,12 +283,16 @@ const SigninProfile = () => { description={t("useYourSecurityKeyForPasswordlessSignIn")} variant="small" /> - {rowsForType(WEB_AUTH_N_PASSWORDLESS, credentials).length !== - 0 && ( + {rowsForType( + CredentialType.WEB_AUTH_N_PASSWORDLESS, + credentials + ).length !== 0 && (