@hono/auth-js 1.0.2 → 1.0.3
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.js +2 -1
- package/dist/index.mjs +2 -1
- package/dist/react.js +20 -9
- package/dist/react.mjs +20 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/dist/react.js
CHANGED
|
@@ -66,8 +66,9 @@ async function fetchData(path, config, logger2, req = {}) {
|
|
|
66
66
|
}
|
|
67
67
|
const res = await fetch(url, options);
|
|
68
68
|
const data = await res.json();
|
|
69
|
-
if (!res.ok)
|
|
69
|
+
if (!res.ok) {
|
|
70
70
|
throw data;
|
|
71
|
+
}
|
|
71
72
|
return data;
|
|
72
73
|
} catch (error) {
|
|
73
74
|
logger2.error(new ClientFetchError(error.message, error));
|
|
@@ -169,10 +170,11 @@ function useSession(options) {
|
|
|
169
170
|
error: "SessionRequired",
|
|
170
171
|
callbackUrl: window.location.href
|
|
171
172
|
})}`;
|
|
172
|
-
if (onUnauthenticated)
|
|
173
|
+
if (onUnauthenticated) {
|
|
173
174
|
onUnauthenticated();
|
|
174
|
-
else
|
|
175
|
+
} else {
|
|
175
176
|
window.location.href = url;
|
|
177
|
+
}
|
|
176
178
|
}
|
|
177
179
|
}, [requiredAndNotLoading, onUnauthenticated]);
|
|
178
180
|
if (requiredAndNotLoading) {
|
|
@@ -195,7 +197,11 @@ async function getSession(params) {
|
|
|
195
197
|
return session;
|
|
196
198
|
}
|
|
197
199
|
async function getCsrfToken() {
|
|
198
|
-
const response = await fetchData(
|
|
200
|
+
const response = await fetchData(
|
|
201
|
+
"csrf",
|
|
202
|
+
authConfigManager.getConfig(),
|
|
203
|
+
logger
|
|
204
|
+
);
|
|
199
205
|
return response?.csrfToken ?? "";
|
|
200
206
|
}
|
|
201
207
|
async function getProviders() {
|
|
@@ -235,8 +241,9 @@ async function signIn(provider, options, authorizationParams) {
|
|
|
235
241
|
if (redirect || !isSupportingReturn) {
|
|
236
242
|
const url = data.url ?? callbackUrl;
|
|
237
243
|
window.location.href = url;
|
|
238
|
-
if (url.includes("#"))
|
|
244
|
+
if (url.includes("#")) {
|
|
239
245
|
window.location.reload();
|
|
246
|
+
}
|
|
240
247
|
return;
|
|
241
248
|
}
|
|
242
249
|
const error = new URL(data.url).searchParams.get("error");
|
|
@@ -269,8 +276,9 @@ async function signOut(options) {
|
|
|
269
276
|
if (options?.redirect ?? true) {
|
|
270
277
|
const url = data.url ?? callbackUrl;
|
|
271
278
|
window.location.href = url;
|
|
272
|
-
if (url.includes("#"))
|
|
279
|
+
if (url.includes("#")) {
|
|
273
280
|
window.location.reload();
|
|
281
|
+
}
|
|
274
282
|
return;
|
|
275
283
|
}
|
|
276
284
|
await __AUTHJS._getSession({ event: "storage" });
|
|
@@ -285,8 +293,9 @@ function SessionProvider(props) {
|
|
|
285
293
|
const hasInitialSession = props.session !== void 0;
|
|
286
294
|
__AUTHJS._lastSync = hasInitialSession ? now() : 0;
|
|
287
295
|
const [session, setSession] = React2.useState(() => {
|
|
288
|
-
if (hasInitialSession)
|
|
296
|
+
if (hasInitialSession) {
|
|
289
297
|
__AUTHJS._session = props.session;
|
|
298
|
+
}
|
|
290
299
|
return props.session;
|
|
291
300
|
});
|
|
292
301
|
const [loading, setLoading] = React2.useState(!hasInitialSession);
|
|
@@ -340,8 +349,9 @@ function SessionProvider(props) {
|
|
|
340
349
|
React2.useEffect(() => {
|
|
341
350
|
const { refetchOnWindowFocus = true } = props;
|
|
342
351
|
const visibilityHandler = () => {
|
|
343
|
-
if (refetchOnWindowFocus && document.visibilityState === "visible")
|
|
352
|
+
if (refetchOnWindowFocus && document.visibilityState === "visible") {
|
|
344
353
|
__AUTHJS._getSession({ event: "visibilitychange" });
|
|
354
|
+
}
|
|
345
355
|
};
|
|
346
356
|
document.addEventListener("visibilitychange", visibilityHandler, false);
|
|
347
357
|
return () => document.removeEventListener("visibilitychange", visibilityHandler, false);
|
|
@@ -363,8 +373,9 @@ function SessionProvider(props) {
|
|
|
363
373
|
data: session,
|
|
364
374
|
status: loading ? "loading" : session ? "authenticated" : "unauthenticated",
|
|
365
375
|
async update(data) {
|
|
366
|
-
if (loading || !session)
|
|
376
|
+
if (loading || !session) {
|
|
367
377
|
return;
|
|
378
|
+
}
|
|
368
379
|
setLoading(true);
|
|
369
380
|
const newSession = await fetchData(
|
|
370
381
|
"session",
|
package/dist/react.mjs
CHANGED
|
@@ -24,8 +24,9 @@ async function fetchData(path, config, logger2, req = {}) {
|
|
|
24
24
|
}
|
|
25
25
|
const res = await fetch(url, options);
|
|
26
26
|
const data = await res.json();
|
|
27
|
-
if (!res.ok)
|
|
27
|
+
if (!res.ok) {
|
|
28
28
|
throw data;
|
|
29
|
+
}
|
|
29
30
|
return data;
|
|
30
31
|
} catch (error) {
|
|
31
32
|
logger2.error(new ClientFetchError(error.message, error));
|
|
@@ -127,10 +128,11 @@ function useSession(options) {
|
|
|
127
128
|
error: "SessionRequired",
|
|
128
129
|
callbackUrl: window.location.href
|
|
129
130
|
})}`;
|
|
130
|
-
if (onUnauthenticated)
|
|
131
|
+
if (onUnauthenticated) {
|
|
131
132
|
onUnauthenticated();
|
|
132
|
-
else
|
|
133
|
+
} else {
|
|
133
134
|
window.location.href = url;
|
|
135
|
+
}
|
|
134
136
|
}
|
|
135
137
|
}, [requiredAndNotLoading, onUnauthenticated]);
|
|
136
138
|
if (requiredAndNotLoading) {
|
|
@@ -153,7 +155,11 @@ async function getSession(params) {
|
|
|
153
155
|
return session;
|
|
154
156
|
}
|
|
155
157
|
async function getCsrfToken() {
|
|
156
|
-
const response = await fetchData(
|
|
158
|
+
const response = await fetchData(
|
|
159
|
+
"csrf",
|
|
160
|
+
authConfigManager.getConfig(),
|
|
161
|
+
logger
|
|
162
|
+
);
|
|
157
163
|
return response?.csrfToken ?? "";
|
|
158
164
|
}
|
|
159
165
|
async function getProviders() {
|
|
@@ -193,8 +199,9 @@ async function signIn(provider, options, authorizationParams) {
|
|
|
193
199
|
if (redirect || !isSupportingReturn) {
|
|
194
200
|
const url = data.url ?? callbackUrl;
|
|
195
201
|
window.location.href = url;
|
|
196
|
-
if (url.includes("#"))
|
|
202
|
+
if (url.includes("#")) {
|
|
197
203
|
window.location.reload();
|
|
204
|
+
}
|
|
198
205
|
return;
|
|
199
206
|
}
|
|
200
207
|
const error = new URL(data.url).searchParams.get("error");
|
|
@@ -227,8 +234,9 @@ async function signOut(options) {
|
|
|
227
234
|
if (options?.redirect ?? true) {
|
|
228
235
|
const url = data.url ?? callbackUrl;
|
|
229
236
|
window.location.href = url;
|
|
230
|
-
if (url.includes("#"))
|
|
237
|
+
if (url.includes("#")) {
|
|
231
238
|
window.location.reload();
|
|
239
|
+
}
|
|
232
240
|
return;
|
|
233
241
|
}
|
|
234
242
|
await __AUTHJS._getSession({ event: "storage" });
|
|
@@ -243,8 +251,9 @@ function SessionProvider(props) {
|
|
|
243
251
|
const hasInitialSession = props.session !== void 0;
|
|
244
252
|
__AUTHJS._lastSync = hasInitialSession ? now() : 0;
|
|
245
253
|
const [session, setSession] = React2.useState(() => {
|
|
246
|
-
if (hasInitialSession)
|
|
254
|
+
if (hasInitialSession) {
|
|
247
255
|
__AUTHJS._session = props.session;
|
|
256
|
+
}
|
|
248
257
|
return props.session;
|
|
249
258
|
});
|
|
250
259
|
const [loading, setLoading] = React2.useState(!hasInitialSession);
|
|
@@ -298,8 +307,9 @@ function SessionProvider(props) {
|
|
|
298
307
|
React2.useEffect(() => {
|
|
299
308
|
const { refetchOnWindowFocus = true } = props;
|
|
300
309
|
const visibilityHandler = () => {
|
|
301
|
-
if (refetchOnWindowFocus && document.visibilityState === "visible")
|
|
310
|
+
if (refetchOnWindowFocus && document.visibilityState === "visible") {
|
|
302
311
|
__AUTHJS._getSession({ event: "visibilitychange" });
|
|
312
|
+
}
|
|
303
313
|
};
|
|
304
314
|
document.addEventListener("visibilitychange", visibilityHandler, false);
|
|
305
315
|
return () => document.removeEventListener("visibilitychange", visibilityHandler, false);
|
|
@@ -321,8 +331,9 @@ function SessionProvider(props) {
|
|
|
321
331
|
data: session,
|
|
322
332
|
status: loading ? "loading" : session ? "authenticated" : "unauthenticated",
|
|
323
333
|
async update(data) {
|
|
324
|
-
if (loading || !session)
|
|
334
|
+
if (loading || !session) {
|
|
325
335
|
return;
|
|
336
|
+
}
|
|
326
337
|
setLoading(true);
|
|
327
338
|
const newSession = await fetchData(
|
|
328
339
|
"session",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/auth-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A third-party Auth js middleware for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"homepage": "https://github.com/honojs/middleware",
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@auth/core": "0.*",
|
|
56
|
-
"hono": "3.*",
|
|
56
|
+
"hono": ">=3.*",
|
|
57
57
|
"react": ">=18"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|