@startsimpli/auth 0.1.6 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/auth",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Shared authentication package for StartSimpli Next.js apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -100,11 +100,27 @@ export function setAccessToken(token: string | null): void {
100
100
  } else {
101
101
  sessionStorage.setItem(TOKEN_STORAGE_KEY, token);
102
102
  }
103
+ // Sync to a cookie so Next.js middleware can check auth state.
104
+ // Vercel rewrites don't reliably pass through HttpOnly Set-Cookie
105
+ // headers from the Django backend, so we set our own.
106
+ _syncAuthCookie(token);
103
107
  return;
104
108
  }
105
109
  _memToken = token;
106
110
  }
107
111
 
112
+ const AUTH_COOKIE_NAME = 'auth_session';
113
+
114
+ function _syncAuthCookie(token: string | null): void {
115
+ if (typeof document === 'undefined') return;
116
+ if (token) {
117
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
118
+ document.cookie = `${AUTH_COOKIE_NAME}=${token}; path=/; max-age=1800; SameSite=Lax${secure}`;
119
+ } else {
120
+ document.cookie = `${AUTH_COOKIE_NAME}=; path=/; max-age=0`;
121
+ }
122
+ }
123
+
108
124
  // --- Internal helpers ---
109
125
 
110
126
  const AUTH_TIMEOUT_MS = 15_000;