Skip to content

Commit 648c93e

Browse files
committed
fix:fix token cache sync.
Signed-off-by: leozhang2018 <leozhang2018@gmail.com>
1 parent ada794a commit 648c93e

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/AdminAccessControl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { getAdminUserKeyAPI, testAdminConnectionAPI } from './api';
7+
import { authStore } from './stores/AuthStore';
78

89
const sdk = window.JSSDK;
910

@@ -43,6 +44,12 @@ async function getToken(code: string): Promise<boolean> {
4344
};
4445
await sdk.storage.setItem('plugin-admin-local-auth', JSON.stringify(localAuthData));
4546

47+
// 同步更新 authStore 缓存,确保请求拦截器能立即获取到新的 Token
48+
await authStore.setPluginAdminAuthData({
49+
user_access_token: localAuthData.user_access_token,
50+
user_key: localAuthData.user_key
51+
});
52+
4653
return true;
4754
} catch (error) {
4855
console.error('Failed to get token:', error);

src/UserAccessControl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { getUserKeyAPI, testUserConnectionAPI } from './api';
7+
import { authStore } from './stores/AuthStore';
78

89
const sdk = window.JSSDK;
910

@@ -43,6 +44,12 @@ async function getToken(code: string): Promise<boolean> {
4344
};
4445
await sdk.storage.setItem('plugin-local-auth', JSON.stringify(localAuthData));
4546

47+
// 同步更新 authStore 缓存,确保请求拦截器能立即获取到新的 Token
48+
await authStore.setPluginUserAuthData({
49+
user_access_token: localAuthData.user_access_token,
50+
user_key: localAuthData.user_key
51+
});
52+
4653
return true;
4754
} catch (error) {
4855
console.error('Failed to get token:', error);

0 commit comments

Comments
 (0)