@bagelink/auth 1.21.3 → 1.21.7

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.
@@ -1,15 +1,21 @@
1
1
  /**
2
- * Gates post-login soft-navigation and expected-401 toast noise during SSO
3
- * callback. The callback view owns a hard redirect (`location.replace`); any
4
- * LOGIN → `router.push` race mounts the app shell early and flashes
5
- * "Authentication required" from premature API calls.
2
+ * Keeps post-login navigation and logged-out 401s quiet during SSO callback.
3
+ * Callback, login-token, and MFA screens own their own redirect (often
4
+ * `location.replace`). A LOGIN → `router.push` race mounts the app shell early.
6
5
  */
7
6
  /** Route names that perform their own post-login navigation. */
8
7
  export declare const POST_LOGIN_OWNER_ROUTES: Set<string>;
9
- export declare function setSsoCallbackInProgress(value: boolean): void;
8
+ export declare function setSsoCallbackInProgress(active: boolean): void;
10
9
  export declare function isSsoCallbackInProgress(): boolean;
11
- /** Public auth paths where a 401 is expected noise, not a user-facing failure. */
12
- export declare function isAuthPublicPath(pathname?: string): boolean;
10
+ export declare function authPathIsPublic(path: string): boolean;
11
+ /**
12
+ * A named route is public only when the host listed it in `noAuthRoutes`.
13
+ * Before the route name exists, fall back to the current auth path.
14
+ */
15
+ export declare function routeIsAuthPublic(route: {
16
+ name?: unknown;
17
+ path?: string;
18
+ } | null | undefined, noAuthRouteNames: readonly string[]): boolean;
13
19
  /**
14
20
  * Whether the default / host LOGIN redirect should run.
15
21
  * Returns false during SSO callback processing and on routes that own redirect.
package/dist/index.cjs CHANGED
@@ -459,6 +459,56 @@ class AuthApi {
459
459
  return this.api.post(`invitations/${token}/accept`, data ?? {});
460
460
  }
461
461
  }
462
+ const POST_LOGIN_OWNER_ROUTES = /* @__PURE__ */ new Set([
463
+ "auth-callback",
464
+ "AuthCallback",
465
+ "Callback",
466
+ // legacy route name in some apps
467
+ "auth-login-token",
468
+ "auth-mfa"
469
+ ]);
470
+ let ssoCallbackInProgress = false;
471
+ function setSsoCallbackInProgress(active) {
472
+ ssoCallbackInProgress = active;
473
+ }
474
+ function isSsoCallbackInProgress() {
475
+ return ssoCallbackInProgress;
476
+ }
477
+ const PUBLIC_AUTH_PATHS = [
478
+ "/login",
479
+ "/signup",
480
+ "/forgot-password",
481
+ "/reset-password",
482
+ "/resetPassword",
483
+ "/otp",
484
+ "/invitation",
485
+ "/unauthorized",
486
+ "/auth/callback",
487
+ "/auth/login-token"
488
+ ];
489
+ function authPathIsPublic(path) {
490
+ const normalized = path.split("?")[0].replace(/\/+$/, "") || "/";
491
+ return PUBLIC_AUTH_PATHS.some((prefix) => normalized === prefix || normalized.startsWith(`${prefix}/`));
492
+ }
493
+ function routeIsAuthPublic(route, noAuthRouteNames) {
494
+ if (typeof (route == null ? void 0 : route.name) === "string") return noAuthRouteNames.includes(route.name);
495
+ const path = (route == null ? void 0 : route.path) ?? (typeof window !== "undefined" ? window.location.pathname : "");
496
+ return authPathIsPublic(path);
497
+ }
498
+ function shouldAutoRedirectAfterLogin(routeName) {
499
+ if (ssoCallbackInProgress) return false;
500
+ if (routeName != null && POST_LOGIN_OWNER_ROUTES.has(String(routeName))) return false;
501
+ return true;
502
+ }
503
+ const callbackGate = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
504
+ __proto__: null,
505
+ POST_LOGIN_OWNER_ROUTES,
506
+ authPathIsPublic,
507
+ isSsoCallbackInProgress,
508
+ routeIsAuthPublic,
509
+ setSsoCallbackInProgress,
510
+ shouldAutoRedirectAfterLogin
511
+ }, Symbol.toStringTag, { value: "Module" }));
462
512
  const INTAKE_WORKFLOW_ID = "fdba1933-0964-4850-b52a-7a4324175790";
463
513
  const DEFAULT_AGENT_ID = "fdba1933-0964-4850-b52a-7a4324175790";
464
514
  const providers = {
@@ -501,37 +551,6 @@ function isMfaRequiredError(error) {
501
551
  const code = ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.code) ?? ((_c = (_b = response == null ? void 0 : response.data) == null ? void 0 : _b.detail) == null ? void 0 : _c.code);
502
552
  return (response == null ? void 0 : response.status) === 403 && (code === "mfa_required" || code === "mfa_enrollment_required");
503
553
  }
504
- const POST_LOGIN_OWNER_ROUTES = /* @__PURE__ */ new Set([
505
- "auth-callback",
506
- "AuthCallback",
507
- "Callback",
508
- // legacy route name in some apps
509
- "auth-login-token",
510
- "auth-mfa"
511
- ]);
512
- let ssoCallbackInProgress = false;
513
- function setSsoCallbackInProgress(value) {
514
- ssoCallbackInProgress = value;
515
- }
516
- function isSsoCallbackInProgress() {
517
- return ssoCallbackInProgress;
518
- }
519
- function isAuthPublicPath(pathname = typeof window !== "undefined" ? window.location.pathname : "") {
520
- return /^\/(login|signup|otp|forgot-password|reset-password|invitation|unauthorized|auth\/)/.test(pathname);
521
- }
522
- function shouldAutoRedirectAfterLogin(routeName) {
523
- if (ssoCallbackInProgress) return false;
524
- if (routeName != null && POST_LOGIN_OWNER_ROUTES.has(String(routeName))) return false;
525
- return true;
526
- }
527
- const callbackGate = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
528
- __proto__: null,
529
- POST_LOGIN_OWNER_ROUTES,
530
- isAuthPublicPath,
531
- isSsoCallbackInProgress,
532
- setSsoCallbackInProgress,
533
- shouldAutoRedirectAfterLogin
534
- }, Symbol.toStringTag, { value: "Module" }));
535
554
  function getRedirectUrl(router2, config) {
536
555
  const redirect2 = router2.currentRoute.value.query[config.queryKey];
537
556
  return redirect2 || config.fallback;
@@ -1134,6 +1153,11 @@ function getRedirectConfig() {
1134
1153
  }
1135
1154
  return redirectConfig;
1136
1155
  }
1156
+ function isAuthPublicPath() {
1157
+ var _a;
1158
+ const route = (_a = autoRedirectRouter == null ? void 0 : autoRedirectRouter.currentRoute) == null ? void 0 : _a.value;
1159
+ return routeIsAuthPublic(route, (redirectConfig == null ? void 0 : redirectConfig.noAuthRoutes) ?? []);
1160
+ }
1137
1161
  function createAuth(params) {
1138
1162
  if (authApi === null) {
1139
1163
  authApi = new AuthApi(params.baseURL, (error) => {
@@ -1243,6 +1267,7 @@ function createAuth(params) {
1243
1267
  function setupAutoRedirect() {
1244
1268
  if (!eventEmitter || !redirectConfig) return;
1245
1269
  eventEmitter.on(AuthState.LOGIN, async () => {
1270
+ if (isSsoCallbackInProgress()) return;
1246
1271
  if (!autoRedirectRouter) {
1247
1272
  console.warn("[Auth] Auto-redirect enabled but router not set. Call auth.use(router) in your app setup.");
1248
1273
  return;
@@ -1731,6 +1756,7 @@ const useAuth$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
1731
1756
  createAuth,
1732
1757
  ensureInitialAuth,
1733
1758
  getRedirectConfig,
1759
+ isAuthPublicPath,
1734
1760
  resetInitialAuth,
1735
1761
  useAuth
1736
1762
  }, Symbol.toStringTag, { value: "Module" }));
@@ -1824,6 +1850,7 @@ exports.SSOError = SSOError;
1824
1850
  exports.StateMismatchError = StateMismatchError;
1825
1851
  exports.accountToUser = accountToUser;
1826
1852
  exports.authGuard = authGuard;
1853
+ exports.authPathIsPublic = authPathIsPublic;
1827
1854
  exports.buildLoginQuery = buildLoginQuery;
1828
1855
  exports.composeGuards = composeGuards;
1829
1856
  exports.createAuth = createAuth;
@@ -1847,6 +1874,7 @@ exports.performRedirect = performRedirect;
1847
1874
  exports.providers = providers;
1848
1875
  exports.resetAuthState = resetAuthState;
1849
1876
  exports.resetInitialAuth = resetInitialAuth;
1877
+ exports.routeIsAuthPublic = routeIsAuthPublic;
1850
1878
  exports.setAuthContext = setAuthContext;
1851
1879
  exports.setSsoCallbackInProgress = setSsoCallbackInProgress;
1852
1880
  exports.shouldAutoRedirectAfterLogin = shouldAutoRedirectAfterLogin;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from './api';
2
+ export * from './callbackGate';
2
3
  export * from './constants';
3
4
  export * from './mfa';
4
- export * from './callbackGate';
5
5
  export * from './redirect';
6
6
  export * from './router';
7
7
  export * from './routes';
package/dist/index.mjs CHANGED
@@ -457,6 +457,56 @@ class AuthApi {
457
457
  return this.api.post(`invitations/${token}/accept`, data ?? {});
458
458
  }
459
459
  }
460
+ const POST_LOGIN_OWNER_ROUTES = /* @__PURE__ */ new Set([
461
+ "auth-callback",
462
+ "AuthCallback",
463
+ "Callback",
464
+ // legacy route name in some apps
465
+ "auth-login-token",
466
+ "auth-mfa"
467
+ ]);
468
+ let ssoCallbackInProgress = false;
469
+ function setSsoCallbackInProgress(active) {
470
+ ssoCallbackInProgress = active;
471
+ }
472
+ function isSsoCallbackInProgress() {
473
+ return ssoCallbackInProgress;
474
+ }
475
+ const PUBLIC_AUTH_PATHS = [
476
+ "/login",
477
+ "/signup",
478
+ "/forgot-password",
479
+ "/reset-password",
480
+ "/resetPassword",
481
+ "/otp",
482
+ "/invitation",
483
+ "/unauthorized",
484
+ "/auth/callback",
485
+ "/auth/login-token"
486
+ ];
487
+ function authPathIsPublic(path) {
488
+ const normalized = path.split("?")[0].replace(/\/+$/, "") || "/";
489
+ return PUBLIC_AUTH_PATHS.some((prefix) => normalized === prefix || normalized.startsWith(`${prefix}/`));
490
+ }
491
+ function routeIsAuthPublic(route, noAuthRouteNames) {
492
+ if (typeof (route == null ? void 0 : route.name) === "string") return noAuthRouteNames.includes(route.name);
493
+ const path = (route == null ? void 0 : route.path) ?? (typeof window !== "undefined" ? window.location.pathname : "");
494
+ return authPathIsPublic(path);
495
+ }
496
+ function shouldAutoRedirectAfterLogin(routeName) {
497
+ if (ssoCallbackInProgress) return false;
498
+ if (routeName != null && POST_LOGIN_OWNER_ROUTES.has(String(routeName))) return false;
499
+ return true;
500
+ }
501
+ const callbackGate = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
502
+ __proto__: null,
503
+ POST_LOGIN_OWNER_ROUTES,
504
+ authPathIsPublic,
505
+ isSsoCallbackInProgress,
506
+ routeIsAuthPublic,
507
+ setSsoCallbackInProgress,
508
+ shouldAutoRedirectAfterLogin
509
+ }, Symbol.toStringTag, { value: "Module" }));
460
510
  const INTAKE_WORKFLOW_ID = "fdba1933-0964-4850-b52a-7a4324175790";
461
511
  const DEFAULT_AGENT_ID = "fdba1933-0964-4850-b52a-7a4324175790";
462
512
  const providers = {
@@ -499,37 +549,6 @@ function isMfaRequiredError(error) {
499
549
  const code = ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.code) ?? ((_c = (_b = response == null ? void 0 : response.data) == null ? void 0 : _b.detail) == null ? void 0 : _c.code);
500
550
  return (response == null ? void 0 : response.status) === 403 && (code === "mfa_required" || code === "mfa_enrollment_required");
501
551
  }
502
- const POST_LOGIN_OWNER_ROUTES = /* @__PURE__ */ new Set([
503
- "auth-callback",
504
- "AuthCallback",
505
- "Callback",
506
- // legacy route name in some apps
507
- "auth-login-token",
508
- "auth-mfa"
509
- ]);
510
- let ssoCallbackInProgress = false;
511
- function setSsoCallbackInProgress(value) {
512
- ssoCallbackInProgress = value;
513
- }
514
- function isSsoCallbackInProgress() {
515
- return ssoCallbackInProgress;
516
- }
517
- function isAuthPublicPath(pathname = typeof window !== "undefined" ? window.location.pathname : "") {
518
- return /^\/(login|signup|otp|forgot-password|reset-password|invitation|unauthorized|auth\/)/.test(pathname);
519
- }
520
- function shouldAutoRedirectAfterLogin(routeName) {
521
- if (ssoCallbackInProgress) return false;
522
- if (routeName != null && POST_LOGIN_OWNER_ROUTES.has(String(routeName))) return false;
523
- return true;
524
- }
525
- const callbackGate = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
526
- __proto__: null,
527
- POST_LOGIN_OWNER_ROUTES,
528
- isAuthPublicPath,
529
- isSsoCallbackInProgress,
530
- setSsoCallbackInProgress,
531
- shouldAutoRedirectAfterLogin
532
- }, Symbol.toStringTag, { value: "Module" }));
533
552
  function getRedirectUrl(router2, config) {
534
553
  const redirect2 = router2.currentRoute.value.query[config.queryKey];
535
554
  return redirect2 || config.fallback;
@@ -1132,6 +1151,11 @@ function getRedirectConfig() {
1132
1151
  }
1133
1152
  return redirectConfig;
1134
1153
  }
1154
+ function isAuthPublicPath() {
1155
+ var _a;
1156
+ const route = (_a = autoRedirectRouter == null ? void 0 : autoRedirectRouter.currentRoute) == null ? void 0 : _a.value;
1157
+ return routeIsAuthPublic(route, (redirectConfig == null ? void 0 : redirectConfig.noAuthRoutes) ?? []);
1158
+ }
1135
1159
  function createAuth(params) {
1136
1160
  if (authApi === null) {
1137
1161
  authApi = new AuthApi(params.baseURL, (error) => {
@@ -1241,6 +1265,7 @@ function createAuth(params) {
1241
1265
  function setupAutoRedirect() {
1242
1266
  if (!eventEmitter || !redirectConfig) return;
1243
1267
  eventEmitter.on(AuthState.LOGIN, async () => {
1268
+ if (isSsoCallbackInProgress()) return;
1244
1269
  if (!autoRedirectRouter) {
1245
1270
  console.warn("[Auth] Auto-redirect enabled but router not set. Call auth.use(router) in your app setup.");
1246
1271
  return;
@@ -1729,6 +1754,7 @@ const useAuth$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
1729
1754
  createAuth,
1730
1755
  ensureInitialAuth,
1731
1756
  getRedirectConfig,
1757
+ isAuthPublicPath,
1732
1758
  resetInitialAuth,
1733
1759
  useAuth
1734
1760
  }, Symbol.toStringTag, { value: "Module" }));
@@ -1823,6 +1849,7 @@ export {
1823
1849
  StateMismatchError,
1824
1850
  accountToUser,
1825
1851
  authGuard,
1852
+ authPathIsPublic,
1826
1853
  buildLoginQuery,
1827
1854
  composeGuards,
1828
1855
  createAuth,
@@ -1846,6 +1873,7 @@ export {
1846
1873
  providers,
1847
1874
  resetAuthState,
1848
1875
  resetInitialAuth,
1876
+ routeIsAuthPublic,
1849
1877
  setAuthContext,
1850
1878
  setSsoCallbackInProgress,
1851
1879
  shouldAutoRedirectAfterLogin,
package/dist/useAuth.d.ts CHANGED
@@ -53,6 +53,8 @@ export declare function resetInitialAuth(): void;
53
53
  * Used internally by router guard
54
54
  */
55
55
  export declare function getRedirectConfig(): NormalizedRedirectConfig;
56
+ /** True on login/signup/callback screens, where a logged-out 401 is expected. */
57
+ export declare function isAuthPublicPath(): boolean;
56
58
  export declare function createAuth(params: InitParams): AuthInstance;
57
59
  export declare function useAuth(): {
58
60
  user: import('vue').ComputedRef<User | null>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/auth",
3
3
  "type": "module",
4
- "version": "1.21.3",
4
+ "version": "1.21.7",
5
5
  "description": "Bagelink auth package",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -1,14 +1,18 @@
1
- import { describe, expect, test } from 'bun:test'
1
+ import { afterEach, describe, expect, it } from 'vitest'
2
2
  import {
3
- isAuthPublicPath,
3
+ authPathIsPublic,
4
4
  isSsoCallbackInProgress,
5
+ routeIsAuthPublic,
5
6
  setSsoCallbackInProgress,
6
7
  shouldAutoRedirectAfterLogin,
7
8
  } from './callbackGate'
8
9
 
9
- describe('callbackGate', () => {
10
- test('tracks SSO callback progress', () => {
10
+ describe('SSO callback gate', () => {
11
+ afterEach(() => {
11
12
  setSsoCallbackInProgress(false)
13
+ })
14
+
15
+ it('tracks whether an SSO callback is in progress', () => {
12
16
  expect(isSsoCallbackInProgress()).toBe(false)
13
17
  setSsoCallbackInProgress(true)
14
18
  expect(isSsoCallbackInProgress()).toBe(true)
@@ -17,20 +21,35 @@ describe('callbackGate', () => {
17
21
  expect(shouldAutoRedirectAfterLogin('home')).toBe(true)
18
22
  })
19
23
 
20
- test('skips soft redirect on post-login owner routes', () => {
21
- setSsoCallbackInProgress(false)
24
+ it('skips soft redirect on post-login owner routes', () => {
22
25
  expect(shouldAutoRedirectAfterLogin('auth-callback')).toBe(false)
23
26
  expect(shouldAutoRedirectAfterLogin('AuthCallback')).toBe(false)
24
27
  expect(shouldAutoRedirectAfterLogin('Callback')).toBe(false)
25
28
  expect(shouldAutoRedirectAfterLogin('auth-mfa')).toBe(false)
29
+ expect(shouldAutoRedirectAfterLogin('auth-login-token')).toBe(false)
26
30
  expect(shouldAutoRedirectAfterLogin('auth-login')).toBe(true)
27
31
  })
32
+ })
33
+
34
+ describe('auth public paths', () => {
35
+ const names = ['auth-login', 'auth-callback']
36
+
37
+ it('treats configured route names as public', () => {
38
+ expect(routeIsAuthPublic({ name: 'auth-login', path: '/login' }, names)).toBe(true)
39
+ expect(routeIsAuthPublic({ name: 'sessions', path: '/sessions' }, names)).toBe(false)
40
+ })
41
+
42
+ it('uses the path only before a route name exists', () => {
43
+ expect(routeIsAuthPublic({ path: '/auth/callback' }, names)).toBe(true)
44
+ expect(routeIsAuthPublic({ path: '/login-history' }, names)).toBe(false)
45
+ expect(authPathIsPublic('/login')).toBe(true)
46
+ expect(authPathIsPublic('/invitation/abc')).toBe(true)
47
+ expect(authPathIsPublic('/resetPassword')).toBe(true)
48
+ expect(authPathIsPublic('/')).toBe(false)
49
+ expect(authPathIsPublic('/people')).toBe(false)
50
+ })
28
51
 
29
- test('detects public auth paths', () => {
30
- expect(isAuthPublicPath('/auth/callback')).toBe(true)
31
- expect(isAuthPublicPath('/login')).toBe(true)
32
- expect(isAuthPublicPath('/invitation/abc')).toBe(true)
33
- expect(isAuthPublicPath('/')).toBe(false)
34
- expect(isAuthPublicPath('/people')).toBe(false)
52
+ it('does not treat a named protected route as public because of its path', () => {
53
+ expect(routeIsAuthPublic({ name: 'sessions', path: '/login' }, names)).toBe(false)
35
54
  })
36
55
  })
@@ -1,8 +1,7 @@
1
1
  /**
2
- * Gates post-login soft-navigation and expected-401 toast noise during SSO
3
- * callback. The callback view owns a hard redirect (`location.replace`); any
4
- * LOGIN → `router.push` race mounts the app shell early and flashes
5
- * "Authentication required" from premature API calls.
2
+ * Keeps post-login navigation and logged-out 401s quiet during SSO callback.
3
+ * Callback, login-token, and MFA screens own their own redirect (often
4
+ * `location.replace`). A LOGIN → `router.push` race mounts the app shell early.
6
5
  */
7
6
 
8
7
  /** Route names that perform their own post-login navigation. */
@@ -16,17 +15,44 @@ export const POST_LOGIN_OWNER_ROUTES = new Set([
16
15
 
17
16
  let ssoCallbackInProgress = false
18
17
 
19
- export function setSsoCallbackInProgress(value: boolean): void {
20
- ssoCallbackInProgress = value
18
+ export function setSsoCallbackInProgress(active: boolean): void {
19
+ ssoCallbackInProgress = active
21
20
  }
22
21
 
23
22
  export function isSsoCallbackInProgress(): boolean {
24
23
  return ssoCallbackInProgress
25
24
  }
26
25
 
27
- /** Public auth paths where a 401 is expected noise, not a user-facing failure. */
28
- export function isAuthPublicPath(pathname = typeof window !== 'undefined' ? window.location.pathname : ''): boolean {
29
- return /^\/(login|signup|otp|forgot-password|reset-password|invitation|unauthorized|auth\/)/.test(pathname)
26
+ /** Paths used before the router has resolved a named route. */
27
+ const PUBLIC_AUTH_PATHS = [
28
+ '/login',
29
+ '/signup',
30
+ '/forgot-password',
31
+ '/reset-password',
32
+ '/resetPassword',
33
+ '/otp',
34
+ '/invitation',
35
+ '/unauthorized',
36
+ '/auth/callback',
37
+ '/auth/login-token',
38
+ ]
39
+
40
+ export function authPathIsPublic(path: string): boolean {
41
+ const normalized = path.split('?')[0].replace(/\/+$/, '') || '/'
42
+ return PUBLIC_AUTH_PATHS.some(prefix => normalized === prefix || normalized.startsWith(`${prefix}/`))
43
+ }
44
+
45
+ /**
46
+ * A named route is public only when the host listed it in `noAuthRoutes`.
47
+ * Before the route name exists, fall back to the current auth path.
48
+ */
49
+ export function routeIsAuthPublic(
50
+ route: { name?: unknown, path?: string } | null | undefined,
51
+ noAuthRouteNames: readonly string[],
52
+ ): boolean {
53
+ if (typeof route?.name === 'string') return noAuthRouteNames.includes(route.name)
54
+ const path = route?.path ?? (typeof window !== 'undefined' ? window.location.pathname : '')
55
+ return authPathIsPublic(path)
30
56
  }
31
57
 
32
58
  /**
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  // Core auth functionality
2
2
  export * from './api'
3
+ export * from './callbackGate'
3
4
  export * from './constants'
4
5
  export * from './mfa'
5
6
 
6
7
  // Redirect utilities
7
- export * from './callbackGate'
8
8
  export * from './redirect'
9
9
 
10
10
  // Router integration
package/src/useAuth.ts CHANGED
@@ -30,6 +30,7 @@ import type {
30
30
  import type { RedirectConfig, NormalizedRedirectConfig } from './types/redirect'
31
31
  import { ref, computed } from 'vue'
32
32
  import { AuthApi } from './api'
33
+ import { isSsoCallbackInProgress, routeIsAuthPublic } from './callbackGate'
33
34
  import { setAuthContext, sso } from './sso'
34
35
  import { AuthState, accountToUser } from './types'
35
36
  import { normalizeRedirectConfig } from './types/redirect'
@@ -120,6 +121,12 @@ export function getRedirectConfig(): NormalizedRedirectConfig {
120
121
  return redirectConfig
121
122
  }
122
123
 
124
+ /** True on login/signup/callback screens, where a logged-out 401 is expected. */
125
+ export function isAuthPublicPath(): boolean {
126
+ const route = autoRedirectRouter?.currentRoute?.value as { name?: unknown, path?: string } | undefined
127
+ return routeIsAuthPublic(route, redirectConfig?.noAuthRoutes ?? [])
128
+ }
129
+
123
130
  // Initialize auth
124
131
  export function createAuth(params: InitParams): AuthInstance {
125
132
  if (authApi === null) {
@@ -253,6 +260,9 @@ function setupAutoRedirect() {
253
260
  if (!eventEmitter || !redirectConfig) return
254
261
 
255
262
  eventEmitter.on(AuthState.LOGIN, async () => {
263
+ // SSO callback pages hard-redirect themselves. A router push here races that navigation.
264
+ if (isSsoCallbackInProgress()) return
265
+
256
266
  // Only auto-redirect if router is available
257
267
  if (!autoRedirectRouter) {
258
268
  console.warn('[Auth] Auto-redirect enabled but router not set. Call auth.use(router) in your app setup.')