From 8abfc4de5c28ffd011a415185dc86aca022382eb Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Sat, 19 Oct 2024 11:48:32 +0900 Subject: [PATCH] feat: support 2fA --- src/lib/constants.ts | 1 + src/popup.tsx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 0b48f6d..694b0e0 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -32,6 +32,7 @@ const STORAGE_PREFIX = "sky_follower_bridge_storage"; export const STORAGE_KEYS = { BSKY_USER_ID: `${STORAGE_PREFIX}_bsky_password`, BSKY_PASSWORD: `${STORAGE_PREFIX}_bsky_user`, + BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT: `${STORAGE_PREFIX}_bsky_show_auth_factor_token_input`, } as const; export const TARGET_URLS_REGEX = { diff --git a/src/popup.tsx b/src/popup.tsx index 92dbd4c..72a62db 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -49,12 +49,21 @@ function IndexPopup() { }); }; + const saveShowAuthFactorTokenInputToStorage = (value: boolean) => { + chrome.storage.local.set({ + [STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT]: value, + }); + }; + const loadCredentialsFromStorage = useCallback(async () => { chrome.storage.local.get( - [STORAGE_KEYS.BSKY_PASSWORD, STORAGE_KEYS.BSKY_USER_ID], + [STORAGE_KEYS.BSKY_PASSWORD, STORAGE_KEYS.BSKY_USER_ID, STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT], (result) => { setPassword(result[STORAGE_KEYS.BSKY_PASSWORD] || ""); setIdentifier(result[STORAGE_KEYS.BSKY_USER_ID] || ""); + setIsShowAuthFactorTokenInput( + result[STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT] || false, + ); }, ); }, []); @@ -111,10 +120,12 @@ function IndexPopup() { if (res.hasError) { if (res.message.includes(AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE)) { setIsShowAuthFactorTokenInput(true); + saveShowAuthFactorTokenInputToStorage(true); } else { setErrorMessage(res.message); } } else { + saveShowAuthFactorTokenInputToStorage(false); window.close(); } } catch (e) {