From 7ca17884f81e4265a3a3f78163ae5cfc5cde3e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 5 Nov 2024 20:02:32 +0100 Subject: [PATCH] pl-fe: fix the settings_store error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- packages/pl-fe/src/reducers/auth.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/pl-fe/src/reducers/auth.ts b/packages/pl-fe/src/reducers/auth.ts index 14675226e..9855bde59 100644 --- a/packages/pl-fe/src/reducers/auth.ts +++ b/packages/pl-fe/src/reducers/auth.ts @@ -261,17 +261,19 @@ const importMastodonPreload = (state: State, data: ImmutableMap) => }); const persistAuthAccount = (account: CredentialAccount) => { - if (account && account.url) { - const key = `authAccount:${account.url}`; - KVStore.getItem(key).then((oldAccount: any) => { - const settings = oldAccount?.settings_store || {}; - if (!account.settings_store) { - account.settings_store = settings; - } - KVStore.setItem(key, account); - }) - .catch(console.error); - } + const persistedAccount = { ...account }; + const key = `authAccount:${account.url}`; + + KVStore.getItem(key).then((oldAccount: any) => { + const settings = oldAccount?.settings_store || {}; + if (!persistedAccount.settings_store) { + persistedAccount.settings_store = settings; + } + KVStore.setItem(key, persistedAccount); + }) + .catch(console.error); + + return persistedAccount; }; const deleteForbiddenToken = (state: State, error: { response: PlfeResponse }, token: string) => { @@ -293,8 +295,7 @@ const reducer = (state: State, action: AnyAction | AuthAction | MeAction | Prelo case AUTH_LOGGED_OUT: return deleteUser(state, action.account); case VERIFY_CREDENTIALS_SUCCESS: - persistAuthAccount(action.account); - return importCredentials(state, action.token, action.account); + return importCredentials(state, action.token, persistAuthAccount(action.account)); case VERIFY_CREDENTIALS_FAIL: return deleteForbiddenToken(state, action.error, action.token); case SWITCH_ACCOUNT: