@shellui/core 0.7.0-alpha.2 → 0.7.0-alpha.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellui/core",
|
|
3
|
-
"version": "0.7.0-alpha.
|
|
3
|
+
"version": "0.7.0-alpha.3",
|
|
4
4
|
"description": "Shellui Core - Core React application runtime",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"workbox-routing": "^7.4.0",
|
|
74
74
|
"workbox-strategies": "^7.4.0",
|
|
75
75
|
"workbox-window": "^7.4.0",
|
|
76
|
-
"@shellui/sdk": "0.7.0-alpha.
|
|
76
|
+
"@shellui/sdk": "0.7.0-alpha.3"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
hasStoredAuthSession,
|
|
28
28
|
inferAccessPendingErrorCode,
|
|
29
29
|
isBffAuthEnabledFromConfig,
|
|
30
|
+
canRestoreStoredSession,
|
|
30
31
|
isSessionExpired,
|
|
31
32
|
isTokenAutoRefreshDisabled,
|
|
32
33
|
logoutBffAuthSession,
|
|
@@ -252,6 +253,17 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
252
253
|
return;
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
// A new tab has the shared profile but not the tab-scoped refresh token. Treat it as
|
|
257
|
+
// signed out instead of a signed-in session with no token. Keep storage: another tab
|
|
258
|
+
// may still own this session.
|
|
259
|
+
if (!canRestoreStoredSession(stored, bffAuthEnabled)) {
|
|
260
|
+
if (!cancelled) {
|
|
261
|
+
setSession(null);
|
|
262
|
+
setIsLoading(false);
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
255
267
|
const applyRestoredSession = async (source: AuthSession) => {
|
|
256
268
|
try {
|
|
257
269
|
const restored = await shareInFlight(restoreRefreshSlot, () =>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { AuthSession } from '../types';
|
|
3
|
+
import { canRestoreStoredSession } from './canRestoreStoredSession';
|
|
4
|
+
|
|
5
|
+
const base = {
|
|
6
|
+
accessToken: '',
|
|
7
|
+
refreshToken: '',
|
|
8
|
+
tokenType: 'bearer',
|
|
9
|
+
expiresAt: Math.floor(Date.now() / 1000) + 3600,
|
|
10
|
+
provider: 'github',
|
|
11
|
+
} as unknown as AuthSession;
|
|
12
|
+
|
|
13
|
+
describe('canRestoreStoredSession', () => {
|
|
14
|
+
it('rejects a profile without tokens, as seen in a new tab', () => {
|
|
15
|
+
expect(canRestoreStoredSession(base, false)).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('accepts a refresh token', () => {
|
|
19
|
+
expect(canRestoreStoredSession({ ...base, refreshToken: 'r' }, false)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('accepts an access token', () => {
|
|
23
|
+
expect(canRestoreStoredSession({ ...base, accessToken: 'a' }, false)).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('accepts a token-less profile when BFF cookies can refresh it', () => {
|
|
27
|
+
expect(canRestoreStoredSession(base, true)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthSession } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether a stored session snapshot can become a signed-in session on boot.
|
|
5
|
+
*
|
|
6
|
+
* The access token lives in memory only and the refresh token is tab-scoped
|
|
7
|
+
* (sessionStorage), while the profile is shared in localStorage. A new tab
|
|
8
|
+
* therefore sees the profile without any token. Without a token, or a refresh
|
|
9
|
+
* token or BFF cookie to get one, the snapshot must not count as signed in.
|
|
10
|
+
*/
|
|
11
|
+
export const canRestoreStoredSession = (stored: AuthSession, bffAuthEnabled: boolean): boolean =>
|
|
12
|
+
Boolean(stored.accessToken || stored.refreshToken || bffAuthEnabled);
|
|
@@ -51,6 +51,7 @@ export { getPreferredBackendProvider } from './getPreferredBackendProvider';
|
|
|
51
51
|
export { getProviderVisual } from './getProviderVisual';
|
|
52
52
|
export { isLoginMethod } from './isLoginMethod';
|
|
53
53
|
export { resolveLoginSettings } from './resolveLoginSettings';
|
|
54
|
+
export { canRestoreStoredSession } from './canRestoreStoredSession';
|
|
54
55
|
export { isSessionExpired } from './isSessionExpired';
|
|
55
56
|
export { isTokenAutoRefreshDisabled } from './isTokenAutoRefreshDisabled';
|
|
56
57
|
export { normalizeAuthSettings } from './normalizeAuthSettings';
|