@everystack/auth 0.4.5 → 0.4.6
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 +4 -4
- package/src/api.ts +17 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everystack/auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "JWT authentication handlers, password hashing, and React auth context",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Scalable Technology, Inc. <licensing@scalable.technology>",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
},
|
|
109
109
|
"dependencies": {
|
|
110
110
|
"bcryptjs": "3.0.3",
|
|
111
|
-
"@everystack/model": "0.4.
|
|
111
|
+
"@everystack/model": "0.4.19"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
114
|
"@everystack/api": ">=0.1.0",
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
"postgres": "3.4.9",
|
|
138
138
|
"ts-jest": "29.4.9",
|
|
139
139
|
"typescript": "5.9.3",
|
|
140
|
-
"@everystack/
|
|
141
|
-
"@everystack/
|
|
140
|
+
"@everystack/server": "0.4.32",
|
|
141
|
+
"@everystack/api": "0.4.2"
|
|
142
142
|
},
|
|
143
143
|
"scripts": {
|
|
144
144
|
"test": "jest",
|
package/src/api.ts
CHANGED
|
@@ -34,17 +34,32 @@ export async function refreshAuthToken(): Promise<string | null> {
|
|
|
34
34
|
headers: { 'Content-Type': 'application/json' },
|
|
35
35
|
body: JSON.stringify({ refreshToken }),
|
|
36
36
|
});
|
|
37
|
-
if (!res.ok)
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
// Server rejected the refresh token (expired/revoked/reused) — the session is over.
|
|
39
|
+
clearStoredTokens();
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
38
42
|
const body = await res.json();
|
|
39
43
|
localStorage.setItem(TOKEN_KEY, body.token);
|
|
40
44
|
localStorage.setItem(REFRESH_KEY, body.refreshToken);
|
|
41
45
|
return body.token;
|
|
42
|
-
} catch {
|
|
46
|
+
} catch {
|
|
47
|
+
// Network-level failure (e.g. offline) — the refresh token may still be
|
|
48
|
+
// valid, so don't wipe the session; just fail this attempt.
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
43
51
|
})().finally(() => { activeRefresh = null; });
|
|
44
52
|
|
|
45
53
|
return activeRefresh;
|
|
46
54
|
}
|
|
47
55
|
|
|
56
|
+
function clearStoredTokens(): void {
|
|
57
|
+
try {
|
|
58
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
59
|
+
localStorage.removeItem(REFRESH_KEY);
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
export const api = createClient({
|
|
49
64
|
baseUrl: '/api',
|
|
50
65
|
getToken: () => {
|