Skip to content

Commit 88cc956

Browse files
committed
fix: removed getThemeFromSDK utility
1 parent 1ff605e commit 88cc956

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/hooks/useCaptcha.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { useCallback, useState } from "react";
22

33
import type { ICaptcha } from "@/components/Captcha/index";
4+
import { extractTokenValue } from "@/utils/helpers/tokenUtils";
45

5-
export const useCaptcha = (
6-
captchaConfig?: ICaptcha,
7-
label?: string,
8-
theme?: "light" | "dark" | "auto"
9-
) => {
6+
export const useCaptcha = (captchaConfig?: ICaptcha, label?: string) => {
107
const isCaptchaEnabled = !!captchaConfig && !!captchaConfig.provider;
118

129
const [isValid, setIsValid] = useState<boolean>(!isCaptchaEnabled);
@@ -15,6 +12,16 @@ export const useCaptcha = (
1512
undefined
1613
);
1714

15+
const getCaptchaTheme = (): "light" | "dark" | "auto" => {
16+
const allowedThemes = ["light", "dark", "auto"] as const;
17+
const rawTheme = extractTokenValue("--ul-theme-captcha-widget");
18+
19+
const isValidTheme = (theme: unknown): theme is "light" | "dark" | "auto" =>
20+
allowedThemes.includes(theme as "light" | "dark" | "auto");
21+
22+
return isValidTheme(rawTheme) ? rawTheme : "auto";
23+
};
24+
1825
const handleValidationChange = useCallback(
1926
(valid: boolean, val?: string, err?: string) => {
2027
setIsValid(valid);
@@ -30,7 +37,7 @@ export const useCaptcha = (
3037
label,
3138
onValidationChange: handleValidationChange,
3239
error: internalError,
33-
theme: theme,
40+
theme: getCaptchaTheme(),
3441
},
3542
captchaValue: value,
3643
isCaptchaSolved: isValid,

src/utils/theme/themeEngine.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,6 @@ export function clearThemeCache(): void {
221221
currentThemeCache = {};
222222
}
223223

224-
export const getCaptchaThemeFromSDK = (
225-
screenInstance: Auth0ScreenInstance
226-
): "light" | "dark" | "auto" => {
227-
const allowedThemes = ["light", "dark", "auto"] as const;
228-
const rawTheme =
229-
screenInstance?.branding?.themes?.default?.colors?.captcha_widget_theme;
230-
231-
// Type guard to check if the raw theme is a valid theme
232-
const isValidTheme = (theme: unknown): theme is "light" | "dark" | "auto" => {
233-
return allowedThemes.includes(theme as "light" | "dark" | "auto");
234-
};
235-
236-
return isValidTheme(rawTheme) ? rawTheme : "auto";
237-
};
238-
239224
export const getCaptchaTheme = (
240225
theme: "light" | "dark" | "auto" | undefined
241226
) => {

0 commit comments

Comments
 (0)