@bagelink/auth 1.15.531 → 1.15.535

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/dist/index.cjs CHANGED
@@ -1600,6 +1600,13 @@ function authGuard() {
1600
1600
  return true;
1601
1601
  } catch (error) {
1602
1602
  console.error("[Auth Guard] Error:", error);
1603
+ if (requiresAuth) {
1604
+ const query = buildLoginQuery(to.fullPath, config);
1605
+ return {
1606
+ name: config.loginRoute,
1607
+ query
1608
+ };
1609
+ }
1603
1610
  return true;
1604
1611
  }
1605
1612
  };
package/dist/index.mjs CHANGED
@@ -1598,6 +1598,13 @@ function authGuard() {
1598
1598
  return true;
1599
1599
  } catch (error) {
1600
1600
  console.error("[Auth Guard] Error:", error);
1601
+ if (requiresAuth) {
1602
+ const query = buildLoginQuery(to.fullPath, config);
1603
+ return {
1604
+ name: config.loginRoute,
1605
+ query
1606
+ };
1607
+ }
1601
1608
  return true;
1602
1609
  }
1603
1610
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/auth",
3
3
  "type": "module",
4
- "version": "1.15.531",
4
+ "version": "1.15.535",
5
5
  "description": "Bagelink auth package",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -0,0 +1,62 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import type { RouteLocationNormalized } from 'vue-router'
3
+
4
+ const authState = vi.hoisted(() => ({
5
+ user: { value: null as object | null },
6
+ ensureInitialAuth: vi.fn<() => Promise<boolean>>(),
7
+ }))
8
+
9
+ vi.mock('./useAuth', () => ({
10
+ useAuth: () => ({ user: authState.user }),
11
+ getRedirectConfig: () => ({
12
+ authMetaKey: 'auth',
13
+ noAuthRoutes: ['Login'],
14
+ authenticatedRedirect: '/',
15
+ loginRoute: 'Login',
16
+ queryKey: 'redirect',
17
+ fallback: '/',
18
+ autoRedirect: true,
19
+ preserveRedirect: true,
20
+ }),
21
+ ensureInitialAuth: authState.ensureInitialAuth,
22
+ resetInitialAuth: vi.fn(),
23
+ }))
24
+
25
+ import { authGuard } from './router'
26
+
27
+ function route(overrides: Partial<RouteLocationNormalized> = {}): RouteLocationNormalized {
28
+ return {
29
+ fullPath: '/protected',
30
+ hash: '',
31
+ matched: [],
32
+ meta: {},
33
+ name: 'Protected',
34
+ params: {},
35
+ path: '/protected',
36
+ query: {},
37
+ redirectedFrom: undefined,
38
+ ...overrides,
39
+ } as RouteLocationNormalized
40
+ }
41
+
42
+ describe('authGuard', () => {
43
+ beforeEach(() => {
44
+ authState.user.value = null
45
+ authState.ensureInitialAuth.mockReset()
46
+ })
47
+
48
+ it('redirects protected routes when auth bootstrap fails', async () => {
49
+ authState.ensureInitialAuth.mockRejectedValueOnce(new Error('auth unavailable'))
50
+
51
+ await expect(authGuard()(route({ meta: { auth: true } }), route())).resolves.toEqual({
52
+ name: 'Login',
53
+ query: { redirect: '/protected' },
54
+ })
55
+ })
56
+
57
+ it('allows public routes when auth bootstrap fails', async () => {
58
+ authState.ensureInitialAuth.mockRejectedValueOnce(new Error('auth unavailable'))
59
+
60
+ await expect(authGuard()(route(), route())).resolves.toBe(true)
61
+ })
62
+ })
package/src/router.ts CHANGED
@@ -73,7 +73,15 @@ export function authGuard() {
73
73
  return true
74
74
  } catch (error) {
75
75
  console.error('[Auth Guard] Error:', error)
76
- // On error, allow navigation but log the issue
76
+ // Never render a protected route when the session could not be
77
+ // established. Public routes remain available during auth outages.
78
+ if (requiresAuth) {
79
+ const query = buildLoginQuery(to.fullPath, config)
80
+ return {
81
+ name: config.loginRoute,
82
+ query,
83
+ }
84
+ }
77
85
  return true
78
86
  }
79
87
  }