UNPKG

@slashid/docusaurus-theme-slashid

Version:
90 lines (88 loc) 2.23 kB
/* ============================================================================ * Copyright (c) SlashID * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import { useMemo } from "react"; import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; import { convertGlobToRegex } from "../../domain"; function isLegacyConfig(config) { if ( config.hasOwnProperty("oidcClientID") && config.hasOwnProperty("oidcProvider") ) { return true; } return false; } const DEFAULT_CONFIG = { orgID: "", forceLogin: false, baseURL: "https://api.slashid.com", sdkURL: "https://cdn.slashid.com/sdk.html", uxMode: "redirect", privateRedirectPath: "/", formConfiguration: { storeLastHandle: true, factors: [ { method: "email_link", }, ], }, }; export const useSlashIDConfig = () => { const { siteConfig } = useDocusaurusContext(); const { slashID } = siteConfig.themeConfig; const safeOptions = useMemo(() => { // handle the legacy theme config if ( isLegacyConfig(slashID) && slashID.oidcClientID && slashID.oidcProvider ) { const { orgID, forceLogin, baseURL, sdkURL, privatePaths, privateRedirectPath, } = slashID; const options = { orgID, forceLogin, baseURL, sdkURL, privatePaths, privateRedirectPath, formConfiguration: { factors: [ { method: "email_link", }, { method: "oidc", options: { client_id: slashID.oidcClientID, provider: slashID.oidcProvider, ux_mode: "popup", }, }, ], }, }; return convertGlobToRegex({ ...DEFAULT_CONFIG, ...options, }); } const optionsWithDefaults = { ...DEFAULT_CONFIG, ...slashID, }; return convertGlobToRegex(optionsWithDefaults); }, [slashID]); return safeOptions; };