From 44825af0c050e499041d556cd4c00995e7a99f85 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 19 Aug 2025 10:50:58 +0300 Subject: [PATCH] feat(react/settings): port OAuth settings --- .../options/multi_factor_authentication.tsx | 52 ++++++++++++++++--- packages/commons/src/lib/server_api.ts | 7 +++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/options/multi_factor_authentication.tsx b/apps/client/src/widgets/type_widgets/options/multi_factor_authentication.tsx index 23623384c..efbc0d972 100644 --- a/apps/client/src/widgets/type_widgets/options/multi_factor_authentication.tsx +++ b/apps/client/src/widgets/type_widgets/options/multi_factor_authentication.tsx @@ -8,11 +8,12 @@ import FormGroup from "../../react/FormGroup" import { FormInlineRadioGroup } from "../../react/FormRadioGroup" import Admonition from "../../react/Admonition" import { useCallback, useEffect, useMemo, useState } from "preact/hooks" -import { TOTPGenerate, TOTPRecoveryKeysResponse, TOTPStatus } from "@triliumnext/commons" +import { OAuthStatus, TOTPGenerate, TOTPRecoveryKeysResponse, TOTPStatus } from "@triliumnext/commons" import server from "../../../services/server" import Button from "../../react/Button" import dialog from "../../../services/dialog" import toast from "../../../services/toast" +import RawHtml from "../../react/RawHtml" export default function MultiFactorAuthenticationSettings() { const [ mfaEnabled, setMfaEnabled ] = useTriliumOptionBool("mfaEnabled"); @@ -54,14 +55,16 @@ function MultiFactorMethod() { ]} /> - - { mfaMethod === "totp" - ? t("multi_factor_authentication.totp_description") - : ""} - + + { mfaMethod === "totp" + ? t("multi_factor_authentication.totp_description") + : } + - { mfaMethod === "totp" && } + { mfaMethod === "totp" + ? + : } ) } @@ -201,4 +204,39 @@ function TotpRecoveryKeys({ values, generateRecoveryKeys }: { values?: string[], /> ); +} + +function OAuthSettings() { + const [ status, setStatus ] = useState(); + + useEffect(() => { + server.get("oauth/status").then((result) => setStatus); + }); + + return ( + + { status?.enabled ? ( +
+ {t("multi_factor_authentication.oauth_user_account")} + + +
+ {t("multi_factor_authentication.oauth_user_email")} + +
+ ) : ( + <> +

{t("multi_factor_authentication.oauth_description_warning")}

+ + { status?.missingVars && ( + + {t("multi_factor_authentication.oauth_missing_vars", { + variables: status.missingVars.map(v => `"${v}"`).join(", ") + })} + + )} + + )} +
+ ) } \ No newline at end of file diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.ts index 6bb2f36fd..69f8a84a0 100644 --- a/packages/commons/src/lib/server_api.ts +++ b/packages/commons/src/lib/server_api.ts @@ -125,3 +125,10 @@ export interface TOTPRecoveryKeysResponse { keysExist?: boolean; usedRecoveryCodes?: string[]; } + +export interface OAuthStatus { + enabled: boolean; + name?: string; + email?: string; + missingVars?: string[]; +}