From 8092a208c79e9acc682076369f8519dfc2a3ed3b Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Sat, 9 Nov 2024 05:50:16 +0900 Subject: [PATCH] fix: stop saving passwords in local storage --- src/popup.tsx | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/popup.tsx b/src/popup.tsx index 41f7efb..022a73a 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -26,7 +26,6 @@ function IndexPopup() { type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]; message: string; }>(null); - const isDisabled = !password || !identifier || isLoading; const isShowErrorMessage = message?.type === MESSAGE_TYPE.ERROR; const isShowSuccessMessage = message?.type === MESSAGE_TYPE.SUCCESS; @@ -44,7 +43,6 @@ function IndexPopup() { const saveCredentialsToStorage = () => { chrome.storage.local.set({ - [STORAGE_KEYS.BSKY_PASSWORD]: password, [STORAGE_KEYS.BSKY_USER_ID]: identifier, }); }; @@ -58,12 +56,10 @@ function IndexPopup() { const loadCredentialsFromStorage = useCallback(async () => { chrome.storage.local.get( [ - 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, @@ -72,10 +68,29 @@ function IndexPopup() { ); }, []); + const validateForm = () => { + if (!password && !identifier) { + setErrorMessage("Error: Please enter your password and identifier."); + return false; + } + if (!password) { + setErrorMessage("Error: Please enter your password."); + return false; + } + if (!identifier) { + setErrorMessage("Error: Please enter your identifier."); + return false; + } + return true; + }; + const searchBskyUser = async (e?: FormEvent) => { if (e) { e.preventDefault(); } + if (!validateForm()) { + return; + } saveCredentialsToStorage(); const [{ url: currentUrl }] = await chrome.tabs.query({ @@ -295,7 +310,7 @@ function IndexPopup() { className={ "disabled:text-gray-600 dark:disabled:bg-gray-700 dark:disabled:text-gray-300 mt-4 normal-case btn btn-primary btn-sm w-full" } - disabled={isDisabled} + disabled={isLoading} > {isLoading && } {isLoading ? "Finding Bluesky Users" : "Find Bluesky Users"}