fix: stop saving passwords in local storage

This commit is contained in:
kawamataryo 2024-11-09 05:50:16 +09:00
parent c483df4cf9
commit 8092a208c7

View File

@ -26,7 +26,6 @@ function IndexPopup() {
type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]; type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE];
message: string; message: string;
}>(null); }>(null);
const isDisabled = !password || !identifier || isLoading;
const isShowErrorMessage = message?.type === MESSAGE_TYPE.ERROR; const isShowErrorMessage = message?.type === MESSAGE_TYPE.ERROR;
const isShowSuccessMessage = message?.type === MESSAGE_TYPE.SUCCESS; const isShowSuccessMessage = message?.type === MESSAGE_TYPE.SUCCESS;
@ -44,7 +43,6 @@ function IndexPopup() {
const saveCredentialsToStorage = () => { const saveCredentialsToStorage = () => {
chrome.storage.local.set({ chrome.storage.local.set({
[STORAGE_KEYS.BSKY_PASSWORD]: password,
[STORAGE_KEYS.BSKY_USER_ID]: identifier, [STORAGE_KEYS.BSKY_USER_ID]: identifier,
}); });
}; };
@ -58,12 +56,10 @@ function IndexPopup() {
const loadCredentialsFromStorage = useCallback(async () => { const loadCredentialsFromStorage = useCallback(async () => {
chrome.storage.local.get( chrome.storage.local.get(
[ [
STORAGE_KEYS.BSKY_PASSWORD,
STORAGE_KEYS.BSKY_USER_ID, STORAGE_KEYS.BSKY_USER_ID,
STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT, STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT,
], ],
(result) => { (result) => {
setPassword(result[STORAGE_KEYS.BSKY_PASSWORD] || "");
setIdentifier(result[STORAGE_KEYS.BSKY_USER_ID] || ""); setIdentifier(result[STORAGE_KEYS.BSKY_USER_ID] || "");
setIsShowAuthFactorTokenInput( setIsShowAuthFactorTokenInput(
result[STORAGE_KEYS.BSKY_SHOW_AUTH_FACTOR_TOKEN_INPUT] || false, 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) => { const searchBskyUser = async (e?: FormEvent) => {
if (e) { if (e) {
e.preventDefault(); e.preventDefault();
} }
if (!validateForm()) {
return;
}
saveCredentialsToStorage(); saveCredentialsToStorage();
const [{ url: currentUrl }] = await chrome.tabs.query({ const [{ url: currentUrl }] = await chrome.tabs.query({
@ -295,7 +310,7 @@ function IndexPopup() {
className={ 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: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 && <span className="w-4 loading loading-spinner" />} {isLoading && <span className="w-4 loading loading-spinner" />}
{isLoading ? "Finding Bluesky Users" : "Find Bluesky Users"} {isLoading ? "Finding Bluesky Users" : "Find Bluesky Users"}