@shellui/core 0.7.0-alpha.8 → 0.7.0-alpha.9

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.8",
3
+ "version": "0.7.0-alpha.9",
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.8"
76
+ "@shellui/sdk": "0.7.0-alpha.9"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "react": "^18.0.0 || ^19.0.0",
@@ -39,6 +39,7 @@ import {
39
39
  type InFlightSlot,
40
40
  } from './utils';
41
41
  import { buildAuthUrlWithNext } from './utils/buildAuthUrlWithNext';
42
+ import { resolveSdkLoginRedirectPath } from './utils/resolveSdkLoginRedirectPath';
42
43
  import {
43
44
  beginDesktopOAuth,
44
45
  clearDesktopPkce,
@@ -942,7 +943,15 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
942
943
  return;
943
944
  }
944
945
 
945
- startOAuth(provider, payload.redirectPath || urls.login, payload.oauthClientId);
946
+ const currentPath =
947
+ typeof window !== 'undefined'
948
+ ? `${window.location.pathname}${window.location.search}`
949
+ : '/';
950
+ startOAuth(
951
+ provider,
952
+ resolveSdkLoginRedirectPath(payload.redirectPath, currentPath),
953
+ payload.oauthClientId,
954
+ );
946
955
  });
947
956
 
948
957
  return () => cleanup();
@@ -4,6 +4,7 @@ export {
4
4
  getShellUILoginDeviceId,
5
5
  } from './clientLoginContext';
6
6
  export { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
7
+ export { resolveSdkLoginRedirectPath } from './resolveSdkLoginRedirectPath';
7
8
  export { getLoginCancelTarget, isPublicNavigationPage } from './loginCancelTarget';
8
9
  export {
9
10
  buildOAuthSessionRedirectTo,
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import urls from '../../../constants/urls';
3
+ import { resolveSdkLoginRedirectPath } from './resolveSdkLoginRedirectPath';
4
+
5
+ describe('resolveSdkLoginRedirectPath', () => {
6
+ it('returns to the callback with the current page as next', () => {
7
+ expect(resolveSdkLoginRedirectPath(undefined, '/account')).toBe(
8
+ `${urls.loginCallback}?next=%2Faccount`,
9
+ );
10
+ expect(resolveSdkLoginRedirectPath('', '/files?tab=shared')).toBe(
11
+ `${urls.loginCallback}?next=%2Ffiles%3Ftab%3Dshared`,
12
+ );
13
+ });
14
+
15
+ it('uses redirectPath as the page after sign-in', () => {
16
+ expect(resolveSdkLoginRedirectPath('/dashboard', '/account')).toBe(
17
+ `${urls.loginCallback}?next=%2Fdashboard`,
18
+ );
19
+ });
20
+
21
+ it('keeps an explicit callback path', () => {
22
+ const callback = `${urls.loginCallback}?next=%2Fapps`;
23
+ expect(resolveSdkLoginRedirectPath(callback, '/account')).toBe(callback);
24
+ expect(resolveSdkLoginRedirectPath(urls.loginCallback, '/account')).toBe(urls.loginCallback);
25
+ });
26
+
27
+ it('falls back to the current page when redirectPath is the login page', () => {
28
+ expect(resolveSdkLoginRedirectPath(urls.login, '/account')).toBe(
29
+ `${urls.loginCallback}?next=%2Faccount`,
30
+ );
31
+ });
32
+
33
+ it('never sends people back to login or to another origin', () => {
34
+ expect(resolveSdkLoginRedirectPath(undefined, urls.login)).toBe(urls.loginCallback);
35
+ expect(resolveSdkLoginRedirectPath(undefined, '/')).toBe(urls.loginCallback);
36
+ expect(resolveSdkLoginRedirectPath('//evil.example.com', '/account')).toBe(
37
+ `${urls.loginCallback}?next=%2Faccount`,
38
+ );
39
+ expect(resolveSdkLoginRedirectPath('https://evil.example.com', '/')).toBe(urls.loginCallback);
40
+ });
41
+ });
@@ -0,0 +1,31 @@
1
+ import urls from '../../../constants/urls';
2
+ import { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
3
+ import { normalizeNextPath } from './normalizeNextPath';
4
+
5
+ const isCallbackPath = (value: string) =>
6
+ value === urls.loginCallback || value.startsWith(`${urls.loginCallback}?`);
7
+
8
+ const pageAfterSignIn = (value: string | null | undefined): string | null => {
9
+ const next = normalizeNextPath(value?.trim() || null);
10
+ return next && !isCallbackPath(next) ? next : null;
11
+ };
12
+
13
+ /**
14
+ * Pick the `redirect_to` path for a `SHELLUI_LOGIN` request from an app.
15
+ *
16
+ * Only the callback route exchanges the OAuth code, so the request always
17
+ * returns there. `redirectPath` names the page to open after sign-in. With no
18
+ * usable `redirectPath`, people come back to the page they started from.
19
+ * An explicit callback path is kept as is.
20
+ */
21
+ export const resolveSdkLoginRedirectPath = (
22
+ redirectPath: string | null | undefined,
23
+ currentPath: string,
24
+ ): string => {
25
+ const requested = redirectPath?.trim();
26
+ if (requested && isCallbackPath(requested)) {
27
+ return requested;
28
+ }
29
+ const next = pageAfterSignIn(requested) ?? pageAfterSignIn(currentPath);
30
+ return buildAuthUrlWithNext(urls.loginCallback, next);
31
+ };
@@ -32,10 +32,12 @@ describe('filterNavigationForAuthState', () => {
32
32
  ]);
33
33
  });
34
34
 
35
- it('hides login and logged-in entries while the session restore is loading', () => {
35
+ it('hides login entries but keeps logged-in entries while the session restore is loading', () => {
36
36
  expect(
37
37
  paths(filterNavigationForAuthState([home, login, dashboard], false, false, true)),
38
- ).toEqual(['']);
39
- expect(filterNavigationForAuthState([accountGroup], false, false, true)).toEqual([]);
38
+ ).toEqual(['', 'dashboard']);
39
+ expect(paths(filterNavigationForAuthState([accountGroup], false, false, true))).toEqual([
40
+ 'dashboard',
41
+ ]);
40
42
  });
41
43
  });
@@ -227,7 +227,8 @@ export function hasLoginNavigationItem(navigation: (NavigationItem | NavigationG
227
227
  * Hide login navigation entries only when authenticated, so custom login entries
228
228
  * can still be used while signed out (e.g. open login in modal/drawer).
229
229
  * While the initial session restore runs (`isAuthLoading`), login entries are hidden too:
230
- * the account skeleton takes their place until the auth state is known.
230
+ * the account skeleton takes their place until the auth state is known. Logged-in only entries
231
+ * stay visible during the restore so the navigation does not pop in after a reload.
231
232
  */
232
233
  export function filterNavigationForAuthState(
233
234
  navigation: (NavigationItem | NavigationGroup)[],
@@ -242,7 +243,7 @@ export function filterNavigationForAuthState(
242
243
  if ('title' in item && 'items' in item) {
243
244
  const group = item as NavigationGroup;
244
245
  const visibleItems = group.items.filter((navItem) => {
245
- if (navItem.hideWhenLoggedOut && !isAuthenticated) return false;
246
+ if (navItem.hideWhenLoggedOut && !isAuthenticated && !isAuthLoading) return false;
246
247
  if (navItem.requiresDevMode && !isDevModeEnabled) return false;
247
248
  if (hideLoginEntries && isLoginNavigationUrl(navItem.url)) return false;
248
249
  return true;
@@ -251,7 +252,7 @@ export function filterNavigationForAuthState(
251
252
  return { ...group, items: visibleItems };
252
253
  }
253
254
  const navItem = item as NavigationItem;
254
- if (navItem.hideWhenLoggedOut && !isAuthenticated) return null;
255
+ if (navItem.hideWhenLoggedOut && !isAuthenticated && !isAuthLoading) return null;
255
256
  if (navItem.requiresDevMode && !isDevModeEnabled) return null;
256
257
  if (hideLoginEntries && isLoginNavigationUrl(navItem.url)) return null;
257
258
  return item;