@oxyhq/services 5.16.40 → 5.16.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/adapters/expo/crypto.js +56 -0
- package/lib/commonjs/adapters/expo/crypto.js.map +1 -0
- package/lib/commonjs/adapters/expo/fetch.js +30 -0
- package/lib/commonjs/adapters/expo/fetch.js.map +1 -0
- package/lib/commonjs/adapters/expo/index.js +48 -0
- package/lib/commonjs/adapters/expo/index.js.map +1 -0
- package/lib/commonjs/adapters/expo/storage.js +201 -0
- package/lib/commonjs/adapters/expo/storage.js.map +1 -0
- package/lib/commonjs/adapters/index.js +41 -0
- package/lib/commonjs/adapters/index.js.map +1 -0
- package/lib/commonjs/adapters/node/crypto.js +40 -0
- package/lib/commonjs/adapters/node/crypto.js.map +1 -0
- package/lib/commonjs/adapters/node/fetch.js +62 -0
- package/lib/commonjs/adapters/node/fetch.js.map +1 -0
- package/lib/commonjs/adapters/node/index.js +34 -0
- package/lib/commonjs/adapters/node/index.js.map +1 -0
- package/lib/commonjs/adapters/node/storage.js +163 -0
- package/lib/commonjs/adapters/node/storage.js.map +1 -0
- package/lib/commonjs/core/identity-session/DeviceManager.js +237 -0
- package/lib/commonjs/core/identity-session/DeviceManager.js.map +1 -0
- package/lib/commonjs/core/identity-session/INTEGRATION_GUIDE.md +287 -0
- package/lib/commonjs/core/identity-session/IdentityManager.js +400 -0
- package/lib/commonjs/core/identity-session/IdentityManager.js.map +1 -0
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js +394 -0
- package/lib/commonjs/core/identity-session/IdentitySessionCore.js.map +1 -0
- package/lib/commonjs/core/identity-session/RefreshManager.js +137 -0
- package/lib/commonjs/core/identity-session/RefreshManager.js.map +1 -0
- package/lib/commonjs/core/identity-session/SessionManager.js +427 -0
- package/lib/commonjs/core/identity-session/SessionManager.js.map +1 -0
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js +24 -0
- package/lib/commonjs/core/identity-session/createIdentitySessionCore.js.map +1 -0
- package/lib/commonjs/core/identity-session/errors.js +176 -0
- package/lib/commonjs/core/identity-session/errors.js.map +1 -0
- package/lib/commonjs/core/identity-session/index.js +80 -0
- package/lib/commonjs/core/identity-session/index.js.map +1 -0
- package/lib/commonjs/core/identity-session/types.js +2 -0
- package/lib/commonjs/core/identity-session/types.js.map +1 -0
- package/lib/commonjs/core/index.js +2 -21
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/index.js +58 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/interfaces.js +7 -0
- package/lib/commonjs/models/interfaces.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +434 -820
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useAvatarPicker.js +52 -0
- package/lib/commonjs/ui/hooks/useAvatarPicker.js.map +1 -0
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js +125 -0
- package/lib/commonjs/ui/hooks/useIdentityTransfer.js.map +1 -0
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js +81 -0
- package/lib/commonjs/ui/hooks/useTransferCodesPersistence.js.map +1 -0
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +7 -2
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +12 -5
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +2 -2
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +6 -6
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/utils/sessionHelpers.js +7 -1
- package/lib/commonjs/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/commonjs/utils/index.js +0 -7
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/sessionUtils.js +8 -1
- package/lib/commonjs/utils/sessionUtils.js.map +1 -1
- package/lib/module/adapters/expo/crypto.js +51 -0
- package/lib/module/adapters/expo/crypto.js.map +1 -0
- package/lib/module/adapters/expo/fetch.js +26 -0
- package/lib/module/adapters/expo/fetch.js.map +1 -0
- package/lib/module/adapters/expo/index.js +45 -0
- package/lib/module/adapters/expo/index.js.map +1 -0
- package/lib/module/adapters/expo/storage.js +198 -0
- package/lib/module/adapters/expo/storage.js.map +1 -0
- package/lib/module/adapters/index.js +38 -0
- package/lib/module/adapters/index.js.map +1 -0
- package/lib/module/adapters/node/crypto.js +36 -0
- package/lib/module/adapters/node/crypto.js.map +1 -0
- package/lib/module/adapters/node/fetch.js +57 -0
- package/lib/module/adapters/node/fetch.js.map +1 -0
- package/lib/module/adapters/node/index.js +31 -0
- package/lib/module/adapters/node/index.js.map +1 -0
- package/lib/module/adapters/node/storage.js +159 -0
- package/lib/module/adapters/node/storage.js.map +1 -0
- package/lib/module/core/identity-session/DeviceManager.js +232 -0
- package/lib/module/core/identity-session/DeviceManager.js.map +1 -0
- package/lib/module/core/identity-session/INTEGRATION_GUIDE.md +287 -0
- package/lib/module/core/identity-session/IdentityManager.js +395 -0
- package/lib/module/core/identity-session/IdentityManager.js.map +1 -0
- package/lib/module/core/identity-session/IdentitySessionCore.js +390 -0
- package/lib/module/core/identity-session/IdentitySessionCore.js.map +1 -0
- package/lib/module/core/identity-session/RefreshManager.js +132 -0
- package/lib/module/core/identity-session/RefreshManager.js.map +1 -0
- package/lib/module/core/identity-session/SessionManager.js +422 -0
- package/lib/module/core/identity-session/SessionManager.js.map +1 -0
- package/lib/module/core/identity-session/createIdentitySessionCore.js +21 -0
- package/lib/module/core/identity-session/createIdentitySessionCore.js.map +1 -0
- package/lib/module/core/identity-session/errors.js +170 -0
- package/lib/module/core/identity-session/errors.js.map +1 -0
- package/lib/module/core/identity-session/index.js +17 -0
- package/lib/module/core/identity-session/index.js.map +1 -0
- package/lib/module/core/identity-session/types.js +2 -0
- package/lib/module/core/identity-session/types.js.map +1 -0
- package/lib/module/core/index.js +2 -3
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/index.js +12 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/interfaces.js +7 -0
- package/lib/module/models/interfaces.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +436 -822
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/hooks/useAvatarPicker.js +48 -0
- package/lib/module/ui/hooks/useAvatarPicker.js.map +1 -0
- package/lib/module/ui/hooks/useIdentityTransfer.js +121 -0
- package/lib/module/ui/hooks/useIdentityTransfer.js.map +1 -0
- package/lib/module/ui/hooks/useTransferCodesPersistence.js +77 -0
- package/lib/module/ui/hooks/useTransferCodesPersistence.js.map +1 -0
- package/lib/module/ui/screens/AccountCenterScreen.js +7 -2
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +12 -5
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +2 -2
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +6 -6
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/utils/sessionHelpers.js +7 -1
- package/lib/module/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/module/utils/index.js +2 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/sessionUtils.js +8 -1
- package/lib/module/utils/sessionUtils.js.map +1 -1
- package/lib/typescript/adapters/expo/crypto.d.ts +17 -0
- package/lib/typescript/adapters/expo/crypto.d.ts.map +1 -0
- package/lib/typescript/adapters/expo/fetch.d.ts +16 -0
- package/lib/typescript/adapters/expo/fetch.d.ts.map +1 -0
- package/lib/typescript/adapters/expo/index.d.ts +23 -0
- package/lib/typescript/adapters/expo/index.d.ts.map +1 -0
- package/lib/typescript/adapters/expo/storage.d.ts +23 -0
- package/lib/typescript/adapters/expo/storage.d.ts.map +1 -0
- package/lib/typescript/adapters/index.d.ts +13 -0
- package/lib/typescript/adapters/index.d.ts.map +1 -0
- package/lib/typescript/adapters/node/crypto.d.ts +17 -0
- package/lib/typescript/adapters/node/crypto.d.ts.map +1 -0
- package/lib/typescript/adapters/node/fetch.d.ts +16 -0
- package/lib/typescript/adapters/node/fetch.d.ts.map +1 -0
- package/lib/typescript/adapters/node/index.d.ts +23 -0
- package/lib/typescript/adapters/node/index.d.ts.map +1 -0
- package/lib/typescript/adapters/node/storage.d.ts +23 -0
- package/lib/typescript/adapters/node/storage.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/DeviceManager.d.ts +64 -0
- package/lib/typescript/core/identity-session/DeviceManager.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/IdentityManager.d.ts +88 -0
- package/lib/typescript/core/identity-session/IdentityManager.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts +141 -0
- package/lib/typescript/core/identity-session/IdentitySessionCore.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/RefreshManager.d.ts +36 -0
- package/lib/typescript/core/identity-session/RefreshManager.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/SessionManager.d.ts +104 -0
- package/lib/typescript/core/identity-session/SessionManager.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts +11 -0
- package/lib/typescript/core/identity-session/createIdentitySessionCore.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/errors.d.ts +63 -0
- package/lib/typescript/core/identity-session/errors.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/index.d.ts +14 -0
- package/lib/typescript/core/identity-session/index.d.ts.map +1 -0
- package/lib/typescript/core/identity-session/types.d.ts +196 -0
- package/lib/typescript/core/identity-session/types.d.ts.map +1 -0
- package/lib/typescript/core/index.d.ts +1 -3
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/core/mixins/index.d.ts +2 -2
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/interfaces.d.ts +5 -36
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/models/session.d.ts +3 -16
- package/lib/typescript/models/session.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +2 -25
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +7 -8
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/useServicesMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +5 -5
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts +18 -0
- package/lib/typescript/ui/hooks/useAvatarPicker.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts +24 -0
- package/lib/typescript/ui/hooks/useIdentityTransfer.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts +6 -0
- package/lib/typescript/ui/hooks/useTransferCodesPersistence.d.ts.map +1 -0
- package/lib/typescript/ui/screens/AccountCenterScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/AccountSettingsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts +1 -0
- package/lib/typescript/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +0 -2
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/sessionUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/expo/crypto.ts +55 -0
- package/src/adapters/expo/fetch.ts +28 -0
- package/src/adapters/expo/index.ts +51 -0
- package/src/adapters/expo/storage.ts +228 -0
- package/src/adapters/index.ts +40 -0
- package/src/adapters/node/crypto.ts +39 -0
- package/src/adapters/node/fetch.ts +59 -0
- package/src/adapters/node/index.ts +37 -0
- package/src/adapters/node/storage.ts +170 -0
- package/src/core/identity-session/DeviceManager.ts +273 -0
- package/src/core/identity-session/INTEGRATION_GUIDE.md +287 -0
- package/src/core/identity-session/IdentityManager.ts +474 -0
- package/src/core/identity-session/IdentitySessionCore.ts +464 -0
- package/src/core/identity-session/RefreshManager.ts +189 -0
- package/src/core/identity-session/SessionManager.ts +500 -0
- package/src/core/identity-session/createIdentitySessionCore.ts +19 -0
- package/src/core/identity-session/errors.ts +197 -0
- package/src/core/identity-session/index.ts +15 -0
- package/src/core/identity-session/types.ts +188 -0
- package/src/core/index.ts +3 -4
- package/src/index.ts +28 -3
- package/src/models/interfaces.ts +12 -39
- package/src/models/session.ts +6 -16
- package/src/ui/context/OxyContext.tsx +442 -871
- package/src/ui/hooks/auth/index.ts +1 -0
- package/src/ui/hooks/useAvatarPicker.ts +62 -0
- package/src/ui/hooks/useIdentityTransfer.ts +135 -0
- package/src/ui/hooks/useTransferCodesPersistence.ts +80 -0
- package/src/ui/screens/AccountCenterScreen.tsx +7 -2
- package/src/ui/screens/AccountSettingsScreen.tsx +15 -8
- package/src/ui/screens/AccountSwitcherScreen.tsx +2 -2
- package/src/ui/screens/ProfileScreen.tsx +10 -10
- package/src/ui/utils/sessionHelpers.ts +7 -0
- package/src/utils/index.ts +1 -2
- package/src/utils/sessionUtils.ts +8 -0
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +0 -732
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +0 -1
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js +0 -73
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js.map +0 -1
- package/lib/commonjs/ui/hooks/useDeviceManagement.js +0 -73
- package/lib/commonjs/ui/hooks/useDeviceManagement.js.map +0 -1
- package/lib/commonjs/ui/hooks/useSessionManagement.js +0 -281
- package/lib/commonjs/ui/hooks/useSessionManagement.js.map +0 -1
- package/lib/commonjs/utils/deviceManager.js +0 -177
- package/lib/commonjs/utils/deviceManager.js.map +0 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +0 -726
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +0 -1
- package/lib/module/ui/context/hooks/useDeviceManagement.js +0 -68
- package/lib/module/ui/context/hooks/useDeviceManagement.js.map +0 -1
- package/lib/module/ui/hooks/useDeviceManagement.js +0 -68
- package/lib/module/ui/hooks/useDeviceManagement.js.map +0 -1
- package/lib/module/ui/hooks/useSessionManagement.js +0 -276
- package/lib/module/ui/hooks/useSessionManagement.js.map +0 -1
- package/lib/module/utils/deviceManager.js +0 -171
- package/lib/module/utils/deviceManager.js.map +0 -1
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +0 -59
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +0 -1
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts +0 -27
- package/lib/typescript/ui/context/hooks/useDeviceManagement.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts +0 -27
- package/lib/typescript/ui/hooks/useDeviceManagement.d.ts.map +0 -1
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts +0 -41
- package/lib/typescript/ui/hooks/useSessionManagement.d.ts.map +0 -1
- package/lib/typescript/utils/deviceManager.d.ts +0 -66
- package/lib/typescript/utils/deviceManager.d.ts.map +0 -1
- package/src/ui/context/hooks/useAuthOperations.ts +0 -801
- package/src/ui/context/hooks/useDeviceManagement.ts +0 -108
- package/src/ui/hooks/useDeviceManagement.ts +0 -108
- package/src/ui/hooks/useSessionManagement.ts +0 -401
- package/src/utils/deviceManager.ts +0 -198
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import type { ApiError } from '../../../models/interfaces';
|
|
3
|
-
import { DeviceManager } from '../../../utils/deviceManager';
|
|
4
|
-
import type { OxyServices } from '../../../core';
|
|
5
|
-
import { handleAuthError } from '../../utils/errorHandlers';
|
|
6
|
-
|
|
7
|
-
export interface UseDeviceManagementOptions {
|
|
8
|
-
oxyServices: OxyServices;
|
|
9
|
-
activeSessionId: string | null;
|
|
10
|
-
onError?: (error: ApiError) => void;
|
|
11
|
-
clearSessionState: () => Promise<void>;
|
|
12
|
-
logger?: (message: string, error?: unknown) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface UseDeviceManagementResult {
|
|
16
|
-
getDeviceSessions: () => Promise<
|
|
17
|
-
Array<{
|
|
18
|
-
sessionId: string;
|
|
19
|
-
deviceId: string;
|
|
20
|
-
deviceName?: string;
|
|
21
|
-
lastActive?: string;
|
|
22
|
-
expiresAt?: string;
|
|
23
|
-
}>
|
|
24
|
-
>;
|
|
25
|
-
logoutAllDeviceSessions: () => Promise<void>;
|
|
26
|
-
updateDeviceName: (deviceName: string) => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Provide device session management helpers tied to the current active session.
|
|
31
|
-
*
|
|
32
|
-
* @param options - Device management configuration
|
|
33
|
-
*/
|
|
34
|
-
export const useDeviceManagement = ({
|
|
35
|
-
oxyServices,
|
|
36
|
-
activeSessionId,
|
|
37
|
-
onError,
|
|
38
|
-
clearSessionState,
|
|
39
|
-
logger,
|
|
40
|
-
}: UseDeviceManagementOptions): UseDeviceManagementResult => {
|
|
41
|
-
const getDeviceSessions = useCallback(async (): Promise<
|
|
42
|
-
Array<{
|
|
43
|
-
sessionId: string;
|
|
44
|
-
deviceId: string;
|
|
45
|
-
deviceName?: string;
|
|
46
|
-
lastActive?: string;
|
|
47
|
-
expiresAt?: string;
|
|
48
|
-
}>
|
|
49
|
-
> => {
|
|
50
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
51
|
-
try {
|
|
52
|
-
return await oxyServices.getDeviceSessions(activeSessionId);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
handleAuthError(error, {
|
|
55
|
-
defaultMessage: 'Failed to get device sessions',
|
|
56
|
-
code: 'GET_DEVICE_SESSIONS_ERROR',
|
|
57
|
-
onError,
|
|
58
|
-
logger,
|
|
59
|
-
});
|
|
60
|
-
throw error instanceof Error ? error : new Error('Failed to get device sessions');
|
|
61
|
-
}
|
|
62
|
-
}, [activeSessionId, logger, onError, oxyServices]);
|
|
63
|
-
|
|
64
|
-
const logoutAllDeviceSessions = useCallback(async (): Promise<void> => {
|
|
65
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
await oxyServices.logoutAllDeviceSessions(activeSessionId);
|
|
69
|
-
await clearSessionState();
|
|
70
|
-
} catch (error) {
|
|
71
|
-
handleAuthError(error, {
|
|
72
|
-
defaultMessage: 'Failed to logout all device sessions',
|
|
73
|
-
code: 'LOGOUT_ALL_DEVICES_ERROR',
|
|
74
|
-
onError,
|
|
75
|
-
logger,
|
|
76
|
-
});
|
|
77
|
-
throw error instanceof Error ? error : new Error('Failed to logout all device sessions');
|
|
78
|
-
}
|
|
79
|
-
}, [activeSessionId, clearSessionState, logger, onError, oxyServices]);
|
|
80
|
-
|
|
81
|
-
const updateDeviceName = useCallback(
|
|
82
|
-
async (deviceName: string): Promise<void> => {
|
|
83
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await oxyServices.updateDeviceName(activeSessionId, deviceName);
|
|
87
|
-
await DeviceManager.updateDeviceName(deviceName);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
handleAuthError(error, {
|
|
90
|
-
defaultMessage: 'Failed to update device name',
|
|
91
|
-
code: 'UPDATE_DEVICE_NAME_ERROR',
|
|
92
|
-
onError,
|
|
93
|
-
logger,
|
|
94
|
-
});
|
|
95
|
-
throw error instanceof Error ? error : new Error('Failed to update device name');
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
[activeSessionId, logger, onError, oxyServices],
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
getDeviceSessions,
|
|
103
|
-
logoutAllDeviceSessions,
|
|
104
|
-
updateDeviceName,
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import type { ApiError } from '../../models/interfaces';
|
|
3
|
-
import { DeviceManager } from '../../utils/deviceManager';
|
|
4
|
-
import type { OxyServices } from '../../core';
|
|
5
|
-
import { handleAuthError } from '../utils/errorHandlers';
|
|
6
|
-
|
|
7
|
-
export interface UseDeviceManagementOptions {
|
|
8
|
-
oxyServices: OxyServices;
|
|
9
|
-
activeSessionId: string | null;
|
|
10
|
-
onError?: (error: ApiError) => void;
|
|
11
|
-
clearSessionState: () => Promise<void>;
|
|
12
|
-
logger?: (message: string, error?: unknown) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface UseDeviceManagementResult {
|
|
16
|
-
getDeviceSessions: () => Promise<
|
|
17
|
-
Array<{
|
|
18
|
-
sessionId: string;
|
|
19
|
-
deviceId: string;
|
|
20
|
-
deviceName?: string;
|
|
21
|
-
lastActive?: string;
|
|
22
|
-
expiresAt?: string;
|
|
23
|
-
}>
|
|
24
|
-
>;
|
|
25
|
-
logoutAllDeviceSessions: () => Promise<void>;
|
|
26
|
-
updateDeviceName: (deviceName: string) => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Provide device session management helpers tied to the current active session.
|
|
31
|
-
*
|
|
32
|
-
* @param options - Device management configuration
|
|
33
|
-
*/
|
|
34
|
-
export const useDeviceManagement = ({
|
|
35
|
-
oxyServices,
|
|
36
|
-
activeSessionId,
|
|
37
|
-
onError,
|
|
38
|
-
clearSessionState,
|
|
39
|
-
logger,
|
|
40
|
-
}: UseDeviceManagementOptions): UseDeviceManagementResult => {
|
|
41
|
-
const getDeviceSessions = useCallback(async (): Promise<
|
|
42
|
-
Array<{
|
|
43
|
-
sessionId: string;
|
|
44
|
-
deviceId: string;
|
|
45
|
-
deviceName?: string;
|
|
46
|
-
lastActive?: string;
|
|
47
|
-
expiresAt?: string;
|
|
48
|
-
}>
|
|
49
|
-
> => {
|
|
50
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
51
|
-
try {
|
|
52
|
-
return await oxyServices.getDeviceSessions(activeSessionId);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
handleAuthError(error, {
|
|
55
|
-
defaultMessage: 'Failed to get device sessions',
|
|
56
|
-
code: 'GET_DEVICE_SESSIONS_ERROR',
|
|
57
|
-
onError,
|
|
58
|
-
logger,
|
|
59
|
-
});
|
|
60
|
-
throw error instanceof Error ? error : new Error('Failed to get device sessions');
|
|
61
|
-
}
|
|
62
|
-
}, [activeSessionId, logger, onError, oxyServices]);
|
|
63
|
-
|
|
64
|
-
const logoutAllDeviceSessions = useCallback(async (): Promise<void> => {
|
|
65
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
await oxyServices.logoutAllDeviceSessions(activeSessionId);
|
|
69
|
-
await clearSessionState();
|
|
70
|
-
} catch (error) {
|
|
71
|
-
handleAuthError(error, {
|
|
72
|
-
defaultMessage: 'Failed to logout all device sessions',
|
|
73
|
-
code: 'LOGOUT_ALL_DEVICES_ERROR',
|
|
74
|
-
onError,
|
|
75
|
-
logger,
|
|
76
|
-
});
|
|
77
|
-
throw error instanceof Error ? error : new Error('Failed to logout all device sessions');
|
|
78
|
-
}
|
|
79
|
-
}, [activeSessionId, clearSessionState, logger, onError, oxyServices]);
|
|
80
|
-
|
|
81
|
-
const updateDeviceName = useCallback(
|
|
82
|
-
async (deviceName: string): Promise<void> => {
|
|
83
|
-
if (!activeSessionId) throw new Error('No active session');
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
await oxyServices.updateDeviceName(activeSessionId, deviceName);
|
|
87
|
-
await DeviceManager.updateDeviceName(deviceName);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
handleAuthError(error, {
|
|
90
|
-
defaultMessage: 'Failed to update device name',
|
|
91
|
-
code: 'UPDATE_DEVICE_NAME_ERROR',
|
|
92
|
-
onError,
|
|
93
|
-
logger,
|
|
94
|
-
});
|
|
95
|
-
throw error instanceof Error ? error : new Error('Failed to update device name');
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
[activeSessionId, logger, onError, oxyServices],
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
getDeviceSessions,
|
|
103
|
-
logoutAllDeviceSessions,
|
|
104
|
-
updateDeviceName,
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import type { ApiError, User } from '../../models/interfaces';
|
|
3
|
-
import type { ClientSession } from '../../models/session';
|
|
4
|
-
import { mergeSessions, normalizeAndSortSessions, sessionsArraysEqual } from '../../utils/sessionUtils';
|
|
5
|
-
import { fetchSessionsWithFallback, mapSessionsToClient, validateSessionBatch } from '../utils/sessionHelpers';
|
|
6
|
-
import { getStorageKeys, type StorageInterface } from '../utils/storageHelpers';
|
|
7
|
-
import { handleAuthError, isInvalidSessionError } from '../utils/errorHandlers';
|
|
8
|
-
import type { OxyServices } from '../../core';
|
|
9
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
10
|
-
import { clearQueryCache } from './queryClient';
|
|
11
|
-
|
|
12
|
-
export interface UseSessionManagementOptions {
|
|
13
|
-
oxyServices: OxyServices;
|
|
14
|
-
storage: StorageInterface | null;
|
|
15
|
-
storageKeyPrefix?: string;
|
|
16
|
-
loginSuccess: (user: User) => void;
|
|
17
|
-
logoutStore: () => void;
|
|
18
|
-
applyLanguagePreference: (user: User) => Promise<void>;
|
|
19
|
-
onAuthStateChange?: (user: User | null) => void;
|
|
20
|
-
onError?: (error: ApiError) => void;
|
|
21
|
-
setAuthError?: (message: string | null) => void;
|
|
22
|
-
logger?: (message: string, error?: unknown) => void;
|
|
23
|
-
setTokenReady?: (ready: boolean) => void;
|
|
24
|
-
queryClient?: QueryClient | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface UseSessionManagementResult {
|
|
28
|
-
sessions: ClientSession[];
|
|
29
|
-
activeSessionId: string | null;
|
|
30
|
-
setActiveSessionId: (sessionId: string | null) => void;
|
|
31
|
-
updateSessions: (incoming: ClientSession[], options?: { merge?: boolean }) => void;
|
|
32
|
-
switchSession: (sessionId: string) => Promise<User>;
|
|
33
|
-
refreshSessions: (activeUserId?: string) => Promise<void>;
|
|
34
|
-
clearSessionState: () => Promise<void>;
|
|
35
|
-
saveActiveSessionId: (sessionId: string) => Promise<void>;
|
|
36
|
-
trackRemovedSession: (sessionId: string) => void;
|
|
37
|
-
storageKeys: ReturnType<typeof getStorageKeys>;
|
|
38
|
-
isRefreshInFlight: boolean;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const DEFAULT_SAVE_ERROR_MESSAGE = 'Failed to save session data';
|
|
42
|
-
const CLEAR_STORAGE_ERROR = 'Failed to clear storage';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Manage session state, persistence, and high-level multi-session operations.
|
|
46
|
-
*
|
|
47
|
-
* @param options - Session management configuration
|
|
48
|
-
*/
|
|
49
|
-
export const useSessionManagement = ({
|
|
50
|
-
oxyServices,
|
|
51
|
-
storage,
|
|
52
|
-
storageKeyPrefix,
|
|
53
|
-
loginSuccess,
|
|
54
|
-
logoutStore,
|
|
55
|
-
applyLanguagePreference,
|
|
56
|
-
onAuthStateChange,
|
|
57
|
-
onError,
|
|
58
|
-
setAuthError,
|
|
59
|
-
logger,
|
|
60
|
-
setTokenReady,
|
|
61
|
-
queryClient,
|
|
62
|
-
}: UseSessionManagementOptions): UseSessionManagementResult => {
|
|
63
|
-
const [sessions, setSessions] = useState<ClientSession[]>([]);
|
|
64
|
-
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
|
65
|
-
|
|
66
|
-
const refreshInFlightRef = useRef<Promise<void> | null>(null);
|
|
67
|
-
const removedSessionsRef = useRef<Set<string>>(new Set());
|
|
68
|
-
const lastRefreshRef = useRef<number>(0);
|
|
69
|
-
|
|
70
|
-
const storageKeys = useMemo(() => getStorageKeys(storageKeyPrefix), [storageKeyPrefix]);
|
|
71
|
-
|
|
72
|
-
const saveSessionIds = useCallback(
|
|
73
|
-
async (sessionIds: string[]): Promise<void> => {
|
|
74
|
-
if (!storage) return;
|
|
75
|
-
try {
|
|
76
|
-
const uniqueIds = Array.from(new Set(sessionIds));
|
|
77
|
-
await storage.setItem(storageKeys.sessionIds, JSON.stringify(uniqueIds));
|
|
78
|
-
} catch (error) {
|
|
79
|
-
if (logger) {
|
|
80
|
-
logger(DEFAULT_SAVE_ERROR_MESSAGE, error);
|
|
81
|
-
} else if (__DEV__) {
|
|
82
|
-
console.warn('Failed to save session IDs:', error);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
[logger, storage, storageKeys.sessionIds],
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const updateSessions = useCallback(
|
|
90
|
-
(incoming: ClientSession[], options: { merge?: boolean } = {}): void => {
|
|
91
|
-
setSessions((prevSessions) => {
|
|
92
|
-
const processed = options.merge
|
|
93
|
-
? mergeSessions(prevSessions, incoming, activeSessionId, false)
|
|
94
|
-
: normalizeAndSortSessions(incoming, activeSessionId, false);
|
|
95
|
-
|
|
96
|
-
if (storage) {
|
|
97
|
-
void saveSessionIds(processed.map((session) => session.sessionId));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (sessionsArraysEqual(prevSessions, processed)) {
|
|
101
|
-
return prevSessions;
|
|
102
|
-
}
|
|
103
|
-
return processed;
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
[activeSessionId, saveSessionIds, storage],
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
const saveActiveSessionId = useCallback(
|
|
110
|
-
async (sessionId: string): Promise<void> => {
|
|
111
|
-
if (!storage) return;
|
|
112
|
-
try {
|
|
113
|
-
await storage.setItem(storageKeys.activeSessionId, sessionId);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
handleAuthError(error, {
|
|
116
|
-
defaultMessage: DEFAULT_SAVE_ERROR_MESSAGE,
|
|
117
|
-
code: 'SESSION_PERSISTENCE_ERROR',
|
|
118
|
-
onError,
|
|
119
|
-
setAuthError,
|
|
120
|
-
logger,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
[logger, onError, setAuthError, storage, storageKeys.activeSessionId],
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const removeActiveSessionId = useCallback(async (): Promise<void> => {
|
|
128
|
-
if (!storage) return;
|
|
129
|
-
try {
|
|
130
|
-
await storage.removeItem(storageKeys.activeSessionId);
|
|
131
|
-
} catch (error) {
|
|
132
|
-
handleAuthError(error, {
|
|
133
|
-
defaultMessage: DEFAULT_SAVE_ERROR_MESSAGE,
|
|
134
|
-
code: 'SESSION_PERSISTENCE_ERROR',
|
|
135
|
-
onError,
|
|
136
|
-
setAuthError,
|
|
137
|
-
logger,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}, [logger, onError, setAuthError, storage, storageKeys.activeSessionId]);
|
|
141
|
-
|
|
142
|
-
const clearSessionStorage = useCallback(async (): Promise<void> => {
|
|
143
|
-
if (!storage) return;
|
|
144
|
-
try {
|
|
145
|
-
await storage.removeItem(storageKeys.activeSessionId);
|
|
146
|
-
await storage.removeItem(storageKeys.sessionIds);
|
|
147
|
-
// Clear identity sync state
|
|
148
|
-
await storage.removeItem('oxy_identity_synced').catch(() => {});
|
|
149
|
-
} catch (error) {
|
|
150
|
-
handleAuthError(error, {
|
|
151
|
-
defaultMessage: CLEAR_STORAGE_ERROR,
|
|
152
|
-
code: 'STORAGE_ERROR',
|
|
153
|
-
onError,
|
|
154
|
-
setAuthError,
|
|
155
|
-
logger,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}, [logger, onError, setAuthError, storage, storageKeys.activeSessionId, storageKeys.sessionIds]);
|
|
159
|
-
|
|
160
|
-
const clearSessionState = useCallback(async (): Promise<void> => {
|
|
161
|
-
setSessions([]);
|
|
162
|
-
setActiveSessionId(null);
|
|
163
|
-
logoutStore();
|
|
164
|
-
|
|
165
|
-
// Clear TanStack Query cache (in-memory)
|
|
166
|
-
if (queryClient) {
|
|
167
|
-
queryClient.clear();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Clear persisted query cache
|
|
171
|
-
if (storage) {
|
|
172
|
-
try {
|
|
173
|
-
await clearQueryCache(storage);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
if (logger) {
|
|
176
|
-
logger('Failed to clear persisted query cache', error);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
await clearSessionStorage();
|
|
182
|
-
onAuthStateChange?.(null);
|
|
183
|
-
}, [clearSessionStorage, logoutStore, onAuthStateChange, queryClient, storage, logger]);
|
|
184
|
-
|
|
185
|
-
const activateSession = useCallback(
|
|
186
|
-
async (sessionId: string, user: User): Promise<void> => {
|
|
187
|
-
await oxyServices.getTokenBySession(sessionId);
|
|
188
|
-
setTokenReady?.(true);
|
|
189
|
-
setActiveSessionId(sessionId);
|
|
190
|
-
loginSuccess(user);
|
|
191
|
-
await saveActiveSessionId(sessionId);
|
|
192
|
-
await applyLanguagePreference(user);
|
|
193
|
-
onAuthStateChange?.(user);
|
|
194
|
-
},
|
|
195
|
-
[
|
|
196
|
-
applyLanguagePreference,
|
|
197
|
-
loginSuccess,
|
|
198
|
-
onAuthStateChange,
|
|
199
|
-
oxyServices,
|
|
200
|
-
saveActiveSessionId,
|
|
201
|
-
setTokenReady,
|
|
202
|
-
],
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
const trackRemovedSession = useCallback((sessionId: string) => {
|
|
206
|
-
removedSessionsRef.current.add(sessionId);
|
|
207
|
-
setTimeout(() => {
|
|
208
|
-
removedSessionsRef.current.delete(sessionId);
|
|
209
|
-
}, 5000);
|
|
210
|
-
}, []);
|
|
211
|
-
|
|
212
|
-
const findReplacementSession = useCallback(
|
|
213
|
-
async (sessionIds: string[]): Promise<User | null> => {
|
|
214
|
-
if (!sessionIds.length) {
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const validationResults = await validateSessionBatch(oxyServices, sessionIds, {
|
|
219
|
-
maxConcurrency: 3,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
const validSession = validationResults.find((result) => result.valid);
|
|
223
|
-
if (!validSession) {
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const validation = await oxyServices.validateSession(validSession.sessionId, {
|
|
228
|
-
useHeaderValidation: true,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
if (!validation?.valid || !validation.user) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const user = validation.user as User;
|
|
236
|
-
await activateSession(validSession.sessionId, user);
|
|
237
|
-
return user;
|
|
238
|
-
},
|
|
239
|
-
[activateSession, oxyServices],
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const switchSession = useCallback(
|
|
243
|
-
async (sessionId: string): Promise<User> => {
|
|
244
|
-
try {
|
|
245
|
-
const validation = await oxyServices.validateSession(sessionId, { useHeaderValidation: true });
|
|
246
|
-
if (!validation?.valid) {
|
|
247
|
-
throw new Error('Session is invalid or expired');
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (!validation.user) {
|
|
251
|
-
throw new Error('User data not available from session validation');
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const user = validation.user as User;
|
|
255
|
-
await activateSession(sessionId, user);
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
const deviceSessions = await fetchSessionsWithFallback(oxyServices, sessionId, {
|
|
259
|
-
fallbackUserId: user.id,
|
|
260
|
-
logger,
|
|
261
|
-
});
|
|
262
|
-
updateSessions(deviceSessions, { merge: true });
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (__DEV__) {
|
|
265
|
-
console.warn('Failed to synchronize sessions after switch:', error);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return user;
|
|
270
|
-
} catch (error) {
|
|
271
|
-
const invalidSession = isInvalidSessionError(error);
|
|
272
|
-
|
|
273
|
-
if (invalidSession) {
|
|
274
|
-
updateSessions(sessions.filter((session) => session.sessionId !== sessionId), {
|
|
275
|
-
merge: false,
|
|
276
|
-
});
|
|
277
|
-
if (sessionId === activeSessionId) {
|
|
278
|
-
const otherSessionIds = sessions
|
|
279
|
-
.filter(
|
|
280
|
-
(session) =>
|
|
281
|
-
session.sessionId !== sessionId && !removedSessionsRef.current.has(session.sessionId),
|
|
282
|
-
)
|
|
283
|
-
.map((session) => session.sessionId);
|
|
284
|
-
|
|
285
|
-
const replacementUser = await findReplacementSession(otherSessionIds);
|
|
286
|
-
if (replacementUser) {
|
|
287
|
-
return replacementUser;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
handleAuthError(error, {
|
|
293
|
-
defaultMessage: 'Failed to switch session',
|
|
294
|
-
code: invalidSession ? 'INVALID_SESSION' : 'SESSION_SWITCH_ERROR',
|
|
295
|
-
onError,
|
|
296
|
-
setAuthError,
|
|
297
|
-
logger,
|
|
298
|
-
});
|
|
299
|
-
throw error instanceof Error ? error : new Error('Failed to switch session');
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
[
|
|
303
|
-
activateSession,
|
|
304
|
-
activeSessionId,
|
|
305
|
-
findReplacementSession,
|
|
306
|
-
logger,
|
|
307
|
-
loginSuccess,
|
|
308
|
-
onError,
|
|
309
|
-
oxyServices,
|
|
310
|
-
sessions,
|
|
311
|
-
setAuthError,
|
|
312
|
-
updateSessions,
|
|
313
|
-
],
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
const refreshSessions = useCallback(
|
|
317
|
-
async (activeUserId?: string): Promise<void> => {
|
|
318
|
-
if (!activeSessionId) return;
|
|
319
|
-
|
|
320
|
-
if (refreshInFlightRef.current) {
|
|
321
|
-
await refreshInFlightRef.current;
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const now = Date.now();
|
|
326
|
-
if (now - lastRefreshRef.current < 500) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
lastRefreshRef.current = now;
|
|
330
|
-
|
|
331
|
-
const refreshPromise = (async () => {
|
|
332
|
-
try {
|
|
333
|
-
const deviceSessions = await fetchSessionsWithFallback(oxyServices, activeSessionId, {
|
|
334
|
-
fallbackUserId: activeUserId,
|
|
335
|
-
logger,
|
|
336
|
-
});
|
|
337
|
-
updateSessions(deviceSessions, { merge: true });
|
|
338
|
-
} catch (error) {
|
|
339
|
-
if (isInvalidSessionError(error)) {
|
|
340
|
-
const otherSessions = sessions
|
|
341
|
-
.filter(
|
|
342
|
-
(session) =>
|
|
343
|
-
session.sessionId !== activeSessionId &&
|
|
344
|
-
!removedSessionsRef.current.has(session.sessionId),
|
|
345
|
-
)
|
|
346
|
-
.map((session) => session.sessionId);
|
|
347
|
-
|
|
348
|
-
const replacementUser = await findReplacementSession(otherSessions);
|
|
349
|
-
if (!replacementUser) {
|
|
350
|
-
await clearSessionState();
|
|
351
|
-
}
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
handleAuthError(error, {
|
|
356
|
-
defaultMessage: 'Failed to refresh sessions',
|
|
357
|
-
code: 'SESSION_REFRESH_ERROR',
|
|
358
|
-
onError,
|
|
359
|
-
setAuthError,
|
|
360
|
-
logger,
|
|
361
|
-
});
|
|
362
|
-
} finally {
|
|
363
|
-
refreshInFlightRef.current = null;
|
|
364
|
-
lastRefreshRef.current = Date.now();
|
|
365
|
-
}
|
|
366
|
-
})();
|
|
367
|
-
|
|
368
|
-
refreshInFlightRef.current = refreshPromise;
|
|
369
|
-
await refreshPromise;
|
|
370
|
-
},
|
|
371
|
-
[
|
|
372
|
-
activeSessionId,
|
|
373
|
-
clearSessionState,
|
|
374
|
-
findReplacementSession,
|
|
375
|
-
logger,
|
|
376
|
-
onError,
|
|
377
|
-
oxyServices,
|
|
378
|
-
sessions,
|
|
379
|
-
setAuthError,
|
|
380
|
-
updateSessions,
|
|
381
|
-
],
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
const isRefreshInFlight = Boolean(refreshInFlightRef.current);
|
|
385
|
-
|
|
386
|
-
return {
|
|
387
|
-
sessions,
|
|
388
|
-
activeSessionId,
|
|
389
|
-
setActiveSessionId,
|
|
390
|
-
updateSessions,
|
|
391
|
-
switchSession,
|
|
392
|
-
refreshSessions,
|
|
393
|
-
clearSessionState,
|
|
394
|
-
saveActiveSessionId,
|
|
395
|
-
trackRemovedSession,
|
|
396
|
-
storageKeys,
|
|
397
|
-
isRefreshInFlight,
|
|
398
|
-
};
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
|