mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
fix(auth): refresh RPC cache before deep-link session store (#2384)
This commit is contained in:
@@ -33,6 +33,13 @@ const waitForOAuthAuthReadiness = vi.hoisted(() =>
|
||||
vi.fn().mockResolvedValue({ ready: true as const })
|
||||
);
|
||||
|
||||
const coreRpcCache = vi.hoisted(() => ({
|
||||
clearCoreRpcUrlCache: vi.fn(),
|
||||
clearCoreRpcTokenCache: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../services/coreRpcClient', () => coreRpcCache);
|
||||
|
||||
vi.mock('../oauthAppVersionGate', async importOriginal => {
|
||||
const actual = await importOriginal<typeof import('../oauthAppVersionGate')>();
|
||||
return {
|
||||
@@ -59,6 +66,8 @@ describe('desktopDeepLinkListener', () => {
|
||||
waitForOAuthAuthReadiness.mockResolvedValue({ ready: true });
|
||||
vi.mocked(storeSession).mockReset();
|
||||
vi.mocked(storeSession).mockResolvedValue(undefined);
|
||||
coreRpcCache.clearCoreRpcUrlCache.mockClear();
|
||||
coreRpcCache.clearCoreRpcTokenCache.mockClear();
|
||||
windowControls.show.mockClear();
|
||||
windowControls.unminimize.mockClear();
|
||||
windowControls.setFocus.mockClear();
|
||||
@@ -172,6 +181,8 @@ describe('desktopDeepLinkListener', () => {
|
||||
await waitForAuthSettled();
|
||||
|
||||
expect(storeSession).toHaveBeenCalledWith('abc', {});
|
||||
expect(coreRpcCache.clearCoreRpcUrlCache).toHaveBeenCalledTimes(1);
|
||||
expect(coreRpcCache.clearCoreRpcTokenCache).toHaveBeenCalledTimes(1);
|
||||
expect(getDeepLinkAuthState().isProcessing).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link';
|
||||
|
||||
import { patchCoreStateSnapshot } from '../lib/coreState/store';
|
||||
import { consumeLoginToken } from '../services/api/authApi';
|
||||
import { clearCoreRpcTokenCache, clearCoreRpcUrlCache } from '../services/coreRpcClient';
|
||||
import {
|
||||
beginDeepLinkAuthProcessing,
|
||||
completeDeepLinkAuthProcessing,
|
||||
@@ -76,6 +77,8 @@ const focusMainWindow = async () => {
|
||||
};
|
||||
|
||||
const applySessionToken = async (sessionToken: string): Promise<void> => {
|
||||
clearCoreRpcUrlCache();
|
||||
clearCoreRpcTokenCache();
|
||||
await storeSession(sessionToken, {});
|
||||
patchCoreStateSnapshot({ snapshot: { sessionToken } });
|
||||
window.dispatchEvent(new CustomEvent(SESSION_TOKEN_UPDATED_EVENT, { detail: { sessionToken } }));
|
||||
|
||||
Reference in New Issue
Block a user