@hono/auth-js 1.0.15 → 1.0.16
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/CHANGELOG.md +103 -0
- package/README.md +3 -0
- package/dist/{index.mjs → index.cjs} +69 -17
- package/dist/{index.d.mts → index.d.cts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -47
- package/dist/{react.mjs → react.cjs} +67 -22
- package/dist/{react.d.mts → react.d.cts} +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +23 -66
- package/package.json +23 -20
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @hono/auth-js
|
|
2
|
+
|
|
3
|
+
## 1.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1170](https://github.com/honojs/middleware/pull/1170) [`7585969171ad4876e7620c7369eb9b638849d0eb`](https://github.com/honojs/middleware/commit/7585969171ad4876e7620c7369eb9b638849d0eb) Thanks [@hambergerpls](https://github.com/hambergerpls)! - fix(auth-js): use HonoRequest.blob() instead of HonoRequest.raw.body()
|
|
8
|
+
|
|
9
|
+
## 1.0.15
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#813](https://github.com/honojs/middleware/pull/813) [`b1c812e50c9388cf7cda893e7c554cedeb24d803`](https://github.com/honojs/middleware/commit/b1c812e50c9388cf7cda893e7c554cedeb24d803) Thanks [@divyam234](https://github.com/divyam234)! - add react 19 in peer dependencies
|
|
14
|
+
|
|
15
|
+
## 1.0.14
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#806](https://github.com/honojs/middleware/pull/806) [`9a2cf452c7000aee4193502da755b2c4352b077d`](https://github.com/honojs/middleware/commit/9a2cf452c7000aee4193502da755b2c4352b077d) Thanks [@985563349](https://github.com/985563349)! - fix cloned request causing request body to be unavailable in middleware
|
|
20
|
+
|
|
21
|
+
## 1.0.13
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#790](https://github.com/honojs/middleware/pull/790) [`ed31c680f7cb4d08985c820e8e1bf051ddc57acd`](https://github.com/honojs/middleware/commit/ed31c680f7cb4d08985c820e8e1bf051ddc57acd) Thanks [@divyam234](https://github.com/divyam234)! - clone request directly for bun
|
|
26
|
+
|
|
27
|
+
## 1.0.12
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#775](https://github.com/honojs/middleware/pull/775) [`c19b51baaf396647f2d6b021e38f083768328b74`](https://github.com/honojs/middleware/commit/c19b51baaf396647f2d6b021e38f083768328b74) Thanks [@divyam234](https://github.com/divyam234)! - refactor session provider
|
|
32
|
+
|
|
33
|
+
## 1.0.11
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- [#769](https://github.com/honojs/middleware/pull/769) [`c2d661aa697bc3800a1b4b6c10ed3589d6d85cf2`](https://github.com/honojs/middleware/commit/c2d661aa697bc3800a1b4b6c10ed3589d6d85cf2) Thanks [@yusukebe](https://github.com/yusukebe)! - fix: remove config.basePath
|
|
38
|
+
|
|
39
|
+
## 1.0.10
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#614](https://github.com/honojs/middleware/pull/614) [`19f3beae1ab33bb3257694c742d1b3e5487a187d`](https://github.com/honojs/middleware/commit/19f3beae1ab33bb3257694c742d1b3e5487a187d) Thanks [@divyam234](https://github.com/divyam234)! - fix immutable headers error in x-forwarded req
|
|
44
|
+
|
|
45
|
+
## 1.0.9
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- [#598](https://github.com/honojs/middleware/pull/598) [`eb7e597aaabce2b2ac6e7809579c44f440c2b8b0`](https://github.com/honojs/middleware/commit/eb7e597aaabce2b2ac6e7809579c44f440c2b8b0) Thanks [@divyam234](https://github.com/divyam234)! - fix bun req cloning
|
|
50
|
+
|
|
51
|
+
## 1.0.8
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#549](https://github.com/honojs/middleware/pull/549) [`d5ebee9c70b5c6e9ecdcadd39805a6a7c481c0ee`](https://github.com/honojs/middleware/commit/d5ebee9c70b5c6e9ecdcadd39805a6a7c481c0ee) Thanks [@divyam234](https://github.com/divyam234)! - handle x-forwarded headers to detect auth url
|
|
56
|
+
|
|
57
|
+
## 1.0.7
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- [#494](https://github.com/honojs/middleware/pull/494) [`300ef2f8bf4761b7b005e0c4ee7cb6ccf3ef810b`](https://github.com/honojs/middleware/commit/300ef2f8bf4761b7b005e0c4ee7cb6ccf3ef810b) Thanks [@divyam234](https://github.com/divyam234)! - fix for ssr
|
|
62
|
+
|
|
63
|
+
## 1.0.6
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- [#486](https://github.com/honojs/middleware/pull/486) [`18959557f45851a0109a63de3e865329c30d4fcc`](https://github.com/honojs/middleware/commit/18959557f45851a0109a63de3e865329c30d4fcc) Thanks [@yusukebe](https://github.com/yusukebe)! - fix: use `env` in `hono/adapter` and add tests
|
|
68
|
+
|
|
69
|
+
## 1.0.5
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- [#481](https://github.com/honojs/middleware/pull/481) [`b8fb9a06c13c3d5988b21e1b286c2a0b5ba99d80`](https://github.com/honojs/middleware/commit/b8fb9a06c13c3d5988b21e1b286c2a0b5ba99d80) Thanks [@DIYgod](https://github.com/DIYgod)! - fix AUTH_URL not working in getAuthUser
|
|
74
|
+
|
|
75
|
+
## 1.0.4
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- [#478](https://github.com/honojs/middleware/pull/478) [`5004ca9c5b6f75c1fca001c26fc70b927c154589`](https://github.com/honojs/middleware/commit/5004ca9c5b6f75c1fca001c26fc70b927c154589) Thanks [@DIYgod](https://github.com/DIYgod)! - fix env AUTH_URL not working
|
|
80
|
+
|
|
81
|
+
## 1.0.3
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- [#380](https://github.com/honojs/middleware/pull/380) [`ea19f6bdeb14216da0880baf5dd5885395c0f008`](https://github.com/honojs/middleware/commit/ea19f6bdeb14216da0880baf5dd5885395c0f008) Thanks [@CarlosZiegler](https://github.com/CarlosZiegler)! - fix: change peer dependency to support v4.0.0
|
|
86
|
+
|
|
87
|
+
## 1.0.2
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#359](https://github.com/honojs/middleware/pull/359) [`4ccda19d3176d9148310bcdb33baf48986433342`](https://github.com/honojs/middleware/commit/4ccda19d3176d9148310bcdb33baf48986433342) Thanks [@divyam234](https://github.com/divyam234)! - Update @auth/core version and set default basePath
|
|
92
|
+
|
|
93
|
+
## 1.0.1
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- [#330](https://github.com/honojs/middleware/pull/330) [`766738e0ea8f5e45739e0ffc4248f132f6313957`](https://github.com/honojs/middleware/commit/766738e0ea8f5e45739e0ffc4248f132f6313957) Thanks [@divyam234](https://github.com/divyam234)! - added react as peer dependency
|
|
98
|
+
|
|
99
|
+
## 1.0.0
|
|
100
|
+
|
|
101
|
+
### Major Changes
|
|
102
|
+
|
|
103
|
+
- [#326](https://github.com/honojs/middleware/pull/326) [`f9859e8fa7e79e1111b8d335d927e7de0309dd7d`](https://github.com/honojs/middleware/commit/f9859e8fa7e79e1111b8d335d927e7de0309dd7d) Thanks [@divyam234](https://github.com/divyam234)! - initial support auth.js with hono
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Auth.js middleware for Hono
|
|
2
2
|
|
|
3
|
+
[](https://codecov.io/github/honojs/middleware)
|
|
4
|
+
|
|
3
5
|
This is a [Auth.js](https://authjs.dev) third-party middleware for [Hono](https://github.com/honojs/hono).
|
|
4
6
|
|
|
5
7
|
This middleware can be used to inject the Auth.js session into the request context.
|
|
@@ -112,6 +114,7 @@ const useSession = () => {
|
|
|
112
114
|
return { session: data, status }
|
|
113
115
|
}
|
|
114
116
|
```
|
|
117
|
+
|
|
115
118
|
For more details on how to Popup Oauth Login see [example](https://github.com/divyam234/next-auth-hono-react)
|
|
116
119
|
|
|
117
120
|
## Author
|
|
@@ -1,11 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
1
20
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
authHandler: () => authHandler,
|
|
24
|
+
getAuthUser: () => getAuthUser,
|
|
25
|
+
initAuthConfig: () => initAuthConfig,
|
|
26
|
+
reqWithEnvUrl: () => reqWithEnvUrl,
|
|
27
|
+
setEnvDefaults: () => setEnvDefaults,
|
|
28
|
+
verifyAuth: () => verifyAuth
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_core = require("@auth/core");
|
|
32
|
+
var import_adapter = require("hono/adapter");
|
|
33
|
+
var import_http_exception = require("hono/http-exception");
|
|
6
34
|
function setEnvDefaults(env2, config) {
|
|
7
35
|
config.secret ??= env2.AUTH_SECRET;
|
|
8
|
-
|
|
36
|
+
(0, import_core.setEnvDefaults)(env2, config);
|
|
9
37
|
}
|
|
10
38
|
function reqWithEnvUrl(req, authUrl) {
|
|
11
39
|
if (authUrl) {
|
|
@@ -13,8 +41,9 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
13
41
|
const authUrlObj = new URL(authUrl);
|
|
14
42
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
15
43
|
for (const prop of props) {
|
|
16
|
-
if (authUrlObj[prop])
|
|
44
|
+
if (authUrlObj[prop]) {
|
|
17
45
|
reqUrlObj[prop] = authUrlObj[prop];
|
|
46
|
+
}
|
|
18
47
|
}
|
|
19
48
|
return new Request(reqUrlObj.href, req);
|
|
20
49
|
}
|
|
@@ -22,15 +51,17 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
22
51
|
const newReq = new Request(url.href, req);
|
|
23
52
|
const proto = newReq.headers.get("x-forwarded-proto");
|
|
24
53
|
const host = newReq.headers.get("x-forwarded-host") ?? newReq.headers.get("host");
|
|
25
|
-
if (proto != null)
|
|
54
|
+
if (proto != null) {
|
|
26
55
|
url.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
56
|
+
}
|
|
27
57
|
if (host != null) {
|
|
28
58
|
url.host = host;
|
|
29
59
|
const portMatch = host.match(/:(\d+)$/);
|
|
30
|
-
if (portMatch)
|
|
60
|
+
if (portMatch) {
|
|
31
61
|
url.port = portMatch[1];
|
|
32
|
-
else
|
|
62
|
+
} else {
|
|
33
63
|
url.port = "";
|
|
64
|
+
}
|
|
34
65
|
newReq.headers.delete("x-forwarded-host");
|
|
35
66
|
newReq.headers.delete("Host");
|
|
36
67
|
newReq.headers.set("Host", host);
|
|
@@ -39,7 +70,7 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
39
70
|
}
|
|
40
71
|
async function getAuthUser(c) {
|
|
41
72
|
const config = c.get("authConfig");
|
|
42
|
-
const ctxEnv = env(c);
|
|
73
|
+
const ctxEnv = (0, import_adapter.env)(c);
|
|
43
74
|
setEnvDefaults(ctxEnv, config);
|
|
44
75
|
const authReq = reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
45
76
|
const origin = new URL(authReq.url).origin;
|
|
@@ -47,7 +78,7 @@ async function getAuthUser(c) {
|
|
|
47
78
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
48
79
|
});
|
|
49
80
|
let authUser = {};
|
|
50
|
-
const response = await Auth(request, {
|
|
81
|
+
const response = await (0, import_core.Auth)(request, {
|
|
51
82
|
...config,
|
|
52
83
|
callbacks: {
|
|
53
84
|
...config.callbacks,
|
|
@@ -70,7 +101,7 @@ function verifyAuth() {
|
|
|
70
101
|
const res = new Response("Unauthorized", {
|
|
71
102
|
status: 401
|
|
72
103
|
});
|
|
73
|
-
throw new HTTPException(401, { res });
|
|
104
|
+
throw new import_http_exception.HTTPException(401, { res });
|
|
74
105
|
}
|
|
75
106
|
c.set("authUser", authUser);
|
|
76
107
|
await next();
|
|
@@ -86,20 +117,41 @@ function initAuthConfig(cb) {
|
|
|
86
117
|
function authHandler() {
|
|
87
118
|
return async (c) => {
|
|
88
119
|
const config = c.get("authConfig");
|
|
89
|
-
const ctxEnv = env(c);
|
|
120
|
+
const ctxEnv = (0, import_adapter.env)(c);
|
|
90
121
|
setEnvDefaults(ctxEnv, config);
|
|
91
122
|
if (!config.secret || config.secret.length === 0) {
|
|
92
|
-
throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
123
|
+
throw new import_http_exception.HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
93
124
|
}
|
|
94
|
-
const
|
|
125
|
+
const body = c.req.raw.body ? await c.req.blob() : void 0;
|
|
126
|
+
const res = await (0, import_core.Auth)(
|
|
127
|
+
reqWithEnvUrl(
|
|
128
|
+
new Request(c.req.raw.url, {
|
|
129
|
+
body,
|
|
130
|
+
cache: c.req.raw.cache,
|
|
131
|
+
credentials: c.req.raw.credentials,
|
|
132
|
+
headers: c.req.raw.headers,
|
|
133
|
+
integrity: c.req.raw.integrity,
|
|
134
|
+
keepalive: c.req.raw.keepalive,
|
|
135
|
+
method: c.req.raw.method,
|
|
136
|
+
mode: c.req.raw.mode,
|
|
137
|
+
redirect: c.req.raw.redirect,
|
|
138
|
+
referrer: c.req.raw.referrer,
|
|
139
|
+
referrerPolicy: c.req.raw.referrerPolicy,
|
|
140
|
+
signal: c.req.raw.signal
|
|
141
|
+
}),
|
|
142
|
+
ctxEnv.AUTH_URL
|
|
143
|
+
),
|
|
144
|
+
config
|
|
145
|
+
);
|
|
95
146
|
return new Response(res.body, res);
|
|
96
147
|
};
|
|
97
148
|
}
|
|
98
|
-
export
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
99
151
|
authHandler,
|
|
100
152
|
getAuthUser,
|
|
101
153
|
initAuthConfig,
|
|
102
154
|
reqWithEnvUrl,
|
|
103
155
|
setEnvDefaults,
|
|
104
156
|
verifyAuth
|
|
105
|
-
};
|
|
157
|
+
});
|
|
@@ -25,7 +25,7 @@ interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
|
25
25
|
}
|
|
26
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
27
|
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
-
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request<unknown, CfProperties<unknown>>;
|
|
29
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
30
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
31
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
|
25
25
|
}
|
|
26
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
27
|
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
-
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request<unknown, CfProperties<unknown>>;
|
|
29
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
30
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
31
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
1
|
// src/index.ts
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getAuthUser: () => getAuthUser,
|
|
25
|
-
initAuthConfig: () => initAuthConfig,
|
|
26
|
-
reqWithEnvUrl: () => reqWithEnvUrl,
|
|
27
|
-
setEnvDefaults: () => setEnvDefaults,
|
|
28
|
-
verifyAuth: () => verifyAuth
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
var import_core = require("@auth/core");
|
|
32
|
-
var import_adapter = require("hono/adapter");
|
|
33
|
-
var import_http_exception = require("hono/http-exception");
|
|
34
|
-
var import_core2 = require("@auth/core");
|
|
2
|
+
import { Auth, setEnvDefaults as coreSetEnvDefaults } from "@auth/core";
|
|
3
|
+
import { env } from "hono/adapter";
|
|
4
|
+
import { HTTPException } from "hono/http-exception";
|
|
35
5
|
function setEnvDefaults(env2, config) {
|
|
36
6
|
config.secret ??= env2.AUTH_SECRET;
|
|
37
|
-
(
|
|
7
|
+
coreSetEnvDefaults(env2, config);
|
|
38
8
|
}
|
|
39
9
|
function reqWithEnvUrl(req, authUrl) {
|
|
40
10
|
if (authUrl) {
|
|
@@ -42,8 +12,9 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
42
12
|
const authUrlObj = new URL(authUrl);
|
|
43
13
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
44
14
|
for (const prop of props) {
|
|
45
|
-
if (authUrlObj[prop])
|
|
15
|
+
if (authUrlObj[prop]) {
|
|
46
16
|
reqUrlObj[prop] = authUrlObj[prop];
|
|
17
|
+
}
|
|
47
18
|
}
|
|
48
19
|
return new Request(reqUrlObj.href, req);
|
|
49
20
|
}
|
|
@@ -51,15 +22,17 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
51
22
|
const newReq = new Request(url.href, req);
|
|
52
23
|
const proto = newReq.headers.get("x-forwarded-proto");
|
|
53
24
|
const host = newReq.headers.get("x-forwarded-host") ?? newReq.headers.get("host");
|
|
54
|
-
if (proto != null)
|
|
25
|
+
if (proto != null) {
|
|
55
26
|
url.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
27
|
+
}
|
|
56
28
|
if (host != null) {
|
|
57
29
|
url.host = host;
|
|
58
30
|
const portMatch = host.match(/:(\d+)$/);
|
|
59
|
-
if (portMatch)
|
|
31
|
+
if (portMatch) {
|
|
60
32
|
url.port = portMatch[1];
|
|
61
|
-
else
|
|
33
|
+
} else {
|
|
62
34
|
url.port = "";
|
|
35
|
+
}
|
|
63
36
|
newReq.headers.delete("x-forwarded-host");
|
|
64
37
|
newReq.headers.delete("Host");
|
|
65
38
|
newReq.headers.set("Host", host);
|
|
@@ -68,7 +41,7 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
68
41
|
}
|
|
69
42
|
async function getAuthUser(c) {
|
|
70
43
|
const config = c.get("authConfig");
|
|
71
|
-
const ctxEnv =
|
|
44
|
+
const ctxEnv = env(c);
|
|
72
45
|
setEnvDefaults(ctxEnv, config);
|
|
73
46
|
const authReq = reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
74
47
|
const origin = new URL(authReq.url).origin;
|
|
@@ -76,7 +49,7 @@ async function getAuthUser(c) {
|
|
|
76
49
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
77
50
|
});
|
|
78
51
|
let authUser = {};
|
|
79
|
-
const response = await
|
|
52
|
+
const response = await Auth(request, {
|
|
80
53
|
...config,
|
|
81
54
|
callbacks: {
|
|
82
55
|
...config.callbacks,
|
|
@@ -99,7 +72,7 @@ function verifyAuth() {
|
|
|
99
72
|
const res = new Response("Unauthorized", {
|
|
100
73
|
status: 401
|
|
101
74
|
});
|
|
102
|
-
throw new
|
|
75
|
+
throw new HTTPException(401, { res });
|
|
103
76
|
}
|
|
104
77
|
c.set("authUser", authUser);
|
|
105
78
|
await next();
|
|
@@ -115,21 +88,40 @@ function initAuthConfig(cb) {
|
|
|
115
88
|
function authHandler() {
|
|
116
89
|
return async (c) => {
|
|
117
90
|
const config = c.get("authConfig");
|
|
118
|
-
const ctxEnv =
|
|
91
|
+
const ctxEnv = env(c);
|
|
119
92
|
setEnvDefaults(ctxEnv, config);
|
|
120
93
|
if (!config.secret || config.secret.length === 0) {
|
|
121
|
-
throw new
|
|
94
|
+
throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
122
95
|
}
|
|
123
|
-
const
|
|
96
|
+
const body = c.req.raw.body ? await c.req.blob() : void 0;
|
|
97
|
+
const res = await Auth(
|
|
98
|
+
reqWithEnvUrl(
|
|
99
|
+
new Request(c.req.raw.url, {
|
|
100
|
+
body,
|
|
101
|
+
cache: c.req.raw.cache,
|
|
102
|
+
credentials: c.req.raw.credentials,
|
|
103
|
+
headers: c.req.raw.headers,
|
|
104
|
+
integrity: c.req.raw.integrity,
|
|
105
|
+
keepalive: c.req.raw.keepalive,
|
|
106
|
+
method: c.req.raw.method,
|
|
107
|
+
mode: c.req.raw.mode,
|
|
108
|
+
redirect: c.req.raw.redirect,
|
|
109
|
+
referrer: c.req.raw.referrer,
|
|
110
|
+
referrerPolicy: c.req.raw.referrerPolicy,
|
|
111
|
+
signal: c.req.raw.signal
|
|
112
|
+
}),
|
|
113
|
+
ctxEnv.AUTH_URL
|
|
114
|
+
),
|
|
115
|
+
config
|
|
116
|
+
);
|
|
124
117
|
return new Response(res.body, res);
|
|
125
118
|
};
|
|
126
119
|
}
|
|
127
|
-
|
|
128
|
-
0 && (module.exports = {
|
|
120
|
+
export {
|
|
129
121
|
authHandler,
|
|
130
122
|
getAuthUser,
|
|
131
123
|
initAuthConfig,
|
|
132
124
|
reqWithEnvUrl,
|
|
133
125
|
setEnvDefaults,
|
|
134
126
|
verifyAuth
|
|
135
|
-
}
|
|
127
|
+
};
|
|
@@ -1,12 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
1
30
|
// src/react.tsx
|
|
2
|
-
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
SessionContext: () => SessionContext,
|
|
34
|
+
SessionProvider: () => SessionProvider,
|
|
35
|
+
authConfigManager: () => authConfigManager,
|
|
36
|
+
getCsrfToken: () => getCsrfToken,
|
|
37
|
+
getProviders: () => getProviders,
|
|
38
|
+
getSession: () => getSession,
|
|
39
|
+
signIn: () => signIn,
|
|
40
|
+
signOut: () => signOut,
|
|
41
|
+
useOauthPopupLogin: () => useOauthPopupLogin,
|
|
42
|
+
useSession: () => useSession
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(react_exports);
|
|
45
|
+
var React = __toESM(require("react"), 1);
|
|
46
|
+
var import_react2 = require("react");
|
|
3
47
|
|
|
4
48
|
// src/client.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var ClientFetchError = class extends AuthError {
|
|
49
|
+
var import_errors = require("@auth/core/errors");
|
|
50
|
+
var import_react = require("react");
|
|
51
|
+
var ClientFetchError = class extends import_errors.AuthError {
|
|
8
52
|
};
|
|
9
|
-
var ClientSessionError = class extends AuthError {
|
|
53
|
+
var ClientSessionError = class extends import_errors.AuthError {
|
|
10
54
|
};
|
|
11
55
|
async function fetchData(path, config, logger2, req = {}) {
|
|
12
56
|
const url = `${config.baseUrl}${config.basePath}/${path}`;
|
|
@@ -34,10 +78,10 @@ async function fetchData(path, config, logger2, req = {}) {
|
|
|
34
78
|
}
|
|
35
79
|
}
|
|
36
80
|
function useOnline() {
|
|
37
|
-
const [isOnline, setIsOnline] = useState(
|
|
81
|
+
const [isOnline, setIsOnline] = (0, import_react.useState)(
|
|
38
82
|
typeof navigator !== "undefined" ? navigator.onLine : false
|
|
39
83
|
);
|
|
40
|
-
useEffect(() => {
|
|
84
|
+
(0, import_react.useEffect)(() => {
|
|
41
85
|
const abortController = new AbortController();
|
|
42
86
|
const { signal } = abortController;
|
|
43
87
|
const setOnline = () => setIsOnline(true);
|
|
@@ -55,7 +99,7 @@ function now() {
|
|
|
55
99
|
}
|
|
56
100
|
function parseUrl(url) {
|
|
57
101
|
const defaultUrl = "http://localhost:3000/api/auth";
|
|
58
|
-
const parsedUrl = new URL(url
|
|
102
|
+
const parsedUrl = new URL(url ? url.startsWith("http") ? url : `https://${url}` : defaultUrl);
|
|
59
103
|
const path = parsedUrl.pathname === "/" ? "/api/auth" : parsedUrl.pathname.replace(/\/$/, "");
|
|
60
104
|
const base = `${parsedUrl.origin}${path}`;
|
|
61
105
|
return {
|
|
@@ -68,7 +112,6 @@ function parseUrl(url) {
|
|
|
68
112
|
}
|
|
69
113
|
|
|
70
114
|
// src/react.tsx
|
|
71
|
-
import { useCallback, useContext, useEffect as useEffect2, useMemo, useState as useState3 } from "react";
|
|
72
115
|
var logger = {
|
|
73
116
|
debug: console.debug,
|
|
74
117
|
error: console.error,
|
|
@@ -112,7 +155,7 @@ function useInitializeSession(hasInitialSession, initialSession) {
|
|
|
112
155
|
const authConfig = authConfigManager.getConfig();
|
|
113
156
|
const [session, setSession] = React.useState(initialSession);
|
|
114
157
|
const [loading, setLoading] = React.useState(!hasInitialSession);
|
|
115
|
-
|
|
158
|
+
(0, import_react2.useEffect)(() => {
|
|
116
159
|
authConfig.fetchSession = async ({ event } = {}) => {
|
|
117
160
|
try {
|
|
118
161
|
const isStorageEvent = event === "storage";
|
|
@@ -144,7 +187,7 @@ function useInitializeSession(hasInitialSession, initialSession) {
|
|
|
144
187
|
return { session, setSession, loading, setLoading };
|
|
145
188
|
}
|
|
146
189
|
function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
147
|
-
|
|
190
|
+
(0, import_react2.useEffect)(() => {
|
|
148
191
|
const abortController = new AbortController();
|
|
149
192
|
const handleVisibilityChange = () => {
|
|
150
193
|
if (refetchOnWindowFocus && document.visibilityState === "visible") {
|
|
@@ -158,7 +201,7 @@ function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
|
158
201
|
}, [refetchOnWindowFocus]);
|
|
159
202
|
}
|
|
160
203
|
function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
161
|
-
|
|
204
|
+
(0, import_react2.useEffect)(() => {
|
|
162
205
|
if (refetchInterval && shouldRefetch) {
|
|
163
206
|
const intervalId = setInterval(() => {
|
|
164
207
|
if (authConfig.session) {
|
|
@@ -212,7 +255,7 @@ function SessionProvider(props) {
|
|
|
212
255
|
const isOnline = useOnline();
|
|
213
256
|
const shouldRefetch = refetchWhenOffline || isOnline;
|
|
214
257
|
useRefetchInterval(authConfig, refetchInterval, shouldRefetch);
|
|
215
|
-
const contextValue = useMemo(
|
|
258
|
+
const contextValue = (0, import_react2.useMemo)(
|
|
216
259
|
() => ({
|
|
217
260
|
data: session,
|
|
218
261
|
status: loading ? "loading" : session ? "authenticated" : "unauthenticated",
|
|
@@ -243,10 +286,10 @@ function useSession(options) {
|
|
|
243
286
|
throw new Error("React Context is unavailable in Server Components");
|
|
244
287
|
}
|
|
245
288
|
const config = authConfigManager.getConfig();
|
|
246
|
-
const session = useContext(SessionContext);
|
|
289
|
+
const session = (0, import_react2.useContext)(SessionContext);
|
|
247
290
|
const { required, onUnauthenticated } = options ?? {};
|
|
248
291
|
const requiredAndNotLoading = required && session?.status === "unauthenticated";
|
|
249
|
-
|
|
292
|
+
(0, import_react2.useEffect)(() => {
|
|
250
293
|
if (requiredAndNotLoading) {
|
|
251
294
|
const url = `${config.baseUrl}${config.basePath}/signin?${new URLSearchParams({
|
|
252
295
|
error: "SessionRequired",
|
|
@@ -354,9 +397,9 @@ var createPopup = ({ url, title, height, width }) => {
|
|
|
354
397
|
};
|
|
355
398
|
var useOauthPopupLogin = (provider, options = {}) => {
|
|
356
399
|
const { width = 500, height = 500, title = "Signin", onSuccess, callbackUrl = "/" } = options;
|
|
357
|
-
const [externalWindow, setExternalWindow] =
|
|
358
|
-
const [state, setState] =
|
|
359
|
-
const popUpSignin = useCallback(async () => {
|
|
400
|
+
const [externalWindow, setExternalWindow] = (0, import_react2.useState)();
|
|
401
|
+
const [state, setState] = (0, import_react2.useState)({ status: "loading" });
|
|
402
|
+
const popUpSignin = (0, import_react2.useCallback)(async () => {
|
|
360
403
|
const res = await signIn(provider, {
|
|
361
404
|
redirect: false,
|
|
362
405
|
callbackUrl
|
|
@@ -374,10 +417,11 @@ var useOauthPopupLogin = (provider, options = {}) => {
|
|
|
374
417
|
})
|
|
375
418
|
);
|
|
376
419
|
}, []);
|
|
377
|
-
|
|
420
|
+
(0, import_react2.useEffect)(() => {
|
|
378
421
|
const handleMessage = (event) => {
|
|
379
|
-
if (event.origin !== window.location.origin)
|
|
422
|
+
if (event.origin !== window.location.origin) {
|
|
380
423
|
return;
|
|
424
|
+
}
|
|
381
425
|
if (event.data.status) {
|
|
382
426
|
setState(event.data);
|
|
383
427
|
if (event.data.status === "success") {
|
|
@@ -394,7 +438,8 @@ var useOauthPopupLogin = (provider, options = {}) => {
|
|
|
394
438
|
}, [externalWindow]);
|
|
395
439
|
return { popUpSignin, ...state };
|
|
396
440
|
};
|
|
397
|
-
export
|
|
441
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
442
|
+
0 && (module.exports = {
|
|
398
443
|
SessionContext,
|
|
399
444
|
SessionProvider,
|
|
400
445
|
authConfigManager,
|
|
@@ -405,4 +450,4 @@ export {
|
|
|
405
450
|
signOut,
|
|
406
451
|
useOauthPopupLogin,
|
|
407
452
|
useSession
|
|
408
|
-
};
|
|
453
|
+
});
|
|
@@ -94,7 +94,7 @@ declare const SessionContext: React$1.Context<{
|
|
|
94
94
|
} | {
|
|
95
95
|
update: UpdateSession;
|
|
96
96
|
data: null;
|
|
97
|
-
status: "
|
|
97
|
+
status: "unauthenticated" | "loading";
|
|
98
98
|
} | undefined>;
|
|
99
99
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
100
100
|
declare function getCsrfToken(): Promise<string>;
|
|
@@ -110,7 +110,7 @@ interface PopupLoginOptions extends Partial<Omit<WindowProps, 'url'>> {
|
|
|
110
110
|
}
|
|
111
111
|
declare const useOauthPopupLogin: (provider: Parameters<typeof signIn>[0], options?: PopupLoginOptions) => {
|
|
112
112
|
status: "loading" | "success" | "errored";
|
|
113
|
-
error?: string
|
|
113
|
+
error?: string;
|
|
114
114
|
popUpSignin: () => Promise<void>;
|
|
115
115
|
};
|
|
116
116
|
|
package/dist/react.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ declare const SessionContext: React$1.Context<{
|
|
|
94
94
|
} | {
|
|
95
95
|
update: UpdateSession;
|
|
96
96
|
data: null;
|
|
97
|
-
status: "
|
|
97
|
+
status: "unauthenticated" | "loading";
|
|
98
98
|
} | undefined>;
|
|
99
99
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
100
100
|
declare function getCsrfToken(): Promise<string>;
|
|
@@ -110,7 +110,7 @@ interface PopupLoginOptions extends Partial<Omit<WindowProps, 'url'>> {
|
|
|
110
110
|
}
|
|
111
111
|
declare const useOauthPopupLogin: (provider: Parameters<typeof signIn>[0], options?: PopupLoginOptions) => {
|
|
112
112
|
status: "loading" | "success" | "errored";
|
|
113
|
-
error?: string
|
|
113
|
+
error?: string;
|
|
114
114
|
popUpSignin: () => Promise<void>;
|
|
115
115
|
};
|
|
116
116
|
|
package/dist/react.js
CHANGED
|
@@ -1,55 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
1
|
// src/react.tsx
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
SessionContext: () => SessionContext,
|
|
34
|
-
SessionProvider: () => SessionProvider,
|
|
35
|
-
authConfigManager: () => authConfigManager,
|
|
36
|
-
getCsrfToken: () => getCsrfToken,
|
|
37
|
-
getProviders: () => getProviders,
|
|
38
|
-
getSession: () => getSession,
|
|
39
|
-
signIn: () => signIn,
|
|
40
|
-
signOut: () => signOut,
|
|
41
|
-
useOauthPopupLogin: () => useOauthPopupLogin,
|
|
42
|
-
useSession: () => useSession
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(react_exports);
|
|
45
|
-
var React = __toESM(require("react"));
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useCallback, useContext, useEffect as useEffect2, useMemo, useState as useState3 } from "react";
|
|
46
4
|
|
|
47
5
|
// src/client.ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var ClientFetchError = class extends
|
|
6
|
+
import { AuthError } from "@auth/core/errors";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
var ClientFetchError = class extends AuthError {
|
|
51
9
|
};
|
|
52
|
-
var ClientSessionError = class extends
|
|
10
|
+
var ClientSessionError = class extends AuthError {
|
|
53
11
|
};
|
|
54
12
|
async function fetchData(path, config, logger2, req = {}) {
|
|
55
13
|
const url = `${config.baseUrl}${config.basePath}/${path}`;
|
|
@@ -77,10 +35,10 @@ async function fetchData(path, config, logger2, req = {}) {
|
|
|
77
35
|
}
|
|
78
36
|
}
|
|
79
37
|
function useOnline() {
|
|
80
|
-
const [isOnline, setIsOnline] =
|
|
38
|
+
const [isOnline, setIsOnline] = useState(
|
|
81
39
|
typeof navigator !== "undefined" ? navigator.onLine : false
|
|
82
40
|
);
|
|
83
|
-
|
|
41
|
+
useEffect(() => {
|
|
84
42
|
const abortController = new AbortController();
|
|
85
43
|
const { signal } = abortController;
|
|
86
44
|
const setOnline = () => setIsOnline(true);
|
|
@@ -98,7 +56,7 @@ function now() {
|
|
|
98
56
|
}
|
|
99
57
|
function parseUrl(url) {
|
|
100
58
|
const defaultUrl = "http://localhost:3000/api/auth";
|
|
101
|
-
const parsedUrl = new URL(url
|
|
59
|
+
const parsedUrl = new URL(url ? url.startsWith("http") ? url : `https://${url}` : defaultUrl);
|
|
102
60
|
const path = parsedUrl.pathname === "/" ? "/api/auth" : parsedUrl.pathname.replace(/\/$/, "");
|
|
103
61
|
const base = `${parsedUrl.origin}${path}`;
|
|
104
62
|
return {
|
|
@@ -111,7 +69,6 @@ function parseUrl(url) {
|
|
|
111
69
|
}
|
|
112
70
|
|
|
113
71
|
// src/react.tsx
|
|
114
|
-
var import_react2 = require("react");
|
|
115
72
|
var logger = {
|
|
116
73
|
debug: console.debug,
|
|
117
74
|
error: console.error,
|
|
@@ -155,7 +112,7 @@ function useInitializeSession(hasInitialSession, initialSession) {
|
|
|
155
112
|
const authConfig = authConfigManager.getConfig();
|
|
156
113
|
const [session, setSession] = React.useState(initialSession);
|
|
157
114
|
const [loading, setLoading] = React.useState(!hasInitialSession);
|
|
158
|
-
(
|
|
115
|
+
useEffect2(() => {
|
|
159
116
|
authConfig.fetchSession = async ({ event } = {}) => {
|
|
160
117
|
try {
|
|
161
118
|
const isStorageEvent = event === "storage";
|
|
@@ -187,7 +144,7 @@ function useInitializeSession(hasInitialSession, initialSession) {
|
|
|
187
144
|
return { session, setSession, loading, setLoading };
|
|
188
145
|
}
|
|
189
146
|
function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
190
|
-
(
|
|
147
|
+
useEffect2(() => {
|
|
191
148
|
const abortController = new AbortController();
|
|
192
149
|
const handleVisibilityChange = () => {
|
|
193
150
|
if (refetchOnWindowFocus && document.visibilityState === "visible") {
|
|
@@ -201,7 +158,7 @@ function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
|
201
158
|
}, [refetchOnWindowFocus]);
|
|
202
159
|
}
|
|
203
160
|
function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
204
|
-
(
|
|
161
|
+
useEffect2(() => {
|
|
205
162
|
if (refetchInterval && shouldRefetch) {
|
|
206
163
|
const intervalId = setInterval(() => {
|
|
207
164
|
if (authConfig.session) {
|
|
@@ -255,7 +212,7 @@ function SessionProvider(props) {
|
|
|
255
212
|
const isOnline = useOnline();
|
|
256
213
|
const shouldRefetch = refetchWhenOffline || isOnline;
|
|
257
214
|
useRefetchInterval(authConfig, refetchInterval, shouldRefetch);
|
|
258
|
-
const contextValue =
|
|
215
|
+
const contextValue = useMemo(
|
|
259
216
|
() => ({
|
|
260
217
|
data: session,
|
|
261
218
|
status: loading ? "loading" : session ? "authenticated" : "unauthenticated",
|
|
@@ -286,10 +243,10 @@ function useSession(options) {
|
|
|
286
243
|
throw new Error("React Context is unavailable in Server Components");
|
|
287
244
|
}
|
|
288
245
|
const config = authConfigManager.getConfig();
|
|
289
|
-
const session =
|
|
246
|
+
const session = useContext(SessionContext);
|
|
290
247
|
const { required, onUnauthenticated } = options ?? {};
|
|
291
248
|
const requiredAndNotLoading = required && session?.status === "unauthenticated";
|
|
292
|
-
(
|
|
249
|
+
useEffect2(() => {
|
|
293
250
|
if (requiredAndNotLoading) {
|
|
294
251
|
const url = `${config.baseUrl}${config.basePath}/signin?${new URLSearchParams({
|
|
295
252
|
error: "SessionRequired",
|
|
@@ -397,9 +354,9 @@ var createPopup = ({ url, title, height, width }) => {
|
|
|
397
354
|
};
|
|
398
355
|
var useOauthPopupLogin = (provider, options = {}) => {
|
|
399
356
|
const { width = 500, height = 500, title = "Signin", onSuccess, callbackUrl = "/" } = options;
|
|
400
|
-
const [externalWindow, setExternalWindow] = (
|
|
401
|
-
const [state, setState] = (
|
|
402
|
-
const popUpSignin =
|
|
357
|
+
const [externalWindow, setExternalWindow] = useState3();
|
|
358
|
+
const [state, setState] = useState3({ status: "loading" });
|
|
359
|
+
const popUpSignin = useCallback(async () => {
|
|
403
360
|
const res = await signIn(provider, {
|
|
404
361
|
redirect: false,
|
|
405
362
|
callbackUrl
|
|
@@ -417,10 +374,11 @@ var useOauthPopupLogin = (provider, options = {}) => {
|
|
|
417
374
|
})
|
|
418
375
|
);
|
|
419
376
|
}, []);
|
|
420
|
-
(
|
|
377
|
+
useEffect2(() => {
|
|
421
378
|
const handleMessage = (event) => {
|
|
422
|
-
if (event.origin !== window.location.origin)
|
|
379
|
+
if (event.origin !== window.location.origin) {
|
|
423
380
|
return;
|
|
381
|
+
}
|
|
424
382
|
if (event.data.status) {
|
|
425
383
|
setState(event.data);
|
|
426
384
|
if (event.data.status === "success") {
|
|
@@ -437,8 +395,7 @@ var useOauthPopupLogin = (provider, options = {}) => {
|
|
|
437
395
|
}, [externalWindow]);
|
|
438
396
|
return { popUpSignin, ...state };
|
|
439
397
|
};
|
|
440
|
-
|
|
441
|
-
0 && (module.exports = {
|
|
398
|
+
export {
|
|
442
399
|
SessionContext,
|
|
443
400
|
SessionProvider,
|
|
444
401
|
authConfigManager,
|
|
@@ -449,4 +406,4 @@ var useOauthPopupLogin = (provider, options = {}) => {
|
|
|
449
406
|
signOut,
|
|
450
407
|
useOauthPopupLogin,
|
|
451
408
|
useSession
|
|
452
|
-
}
|
|
409
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/auth-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "A third-party Auth js middleware for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"import": {
|
|
9
|
-
"types": "./dist/index.d.mts",
|
|
10
|
-
"default": "./dist/index.mjs"
|
|
11
|
-
},
|
|
12
|
-
"require": {
|
|
13
10
|
"types": "./dist/index.d.ts",
|
|
14
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
"./react": {
|
|
18
19
|
"import": {
|
|
19
|
-
"types": "./dist/react.d.mts",
|
|
20
|
-
"default": "./dist/react.mjs"
|
|
21
|
-
},
|
|
22
|
-
"require": {
|
|
23
20
|
"types": "./dist/react.d.ts",
|
|
24
21
|
"default": "./dist/react.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/react.d.cts",
|
|
25
|
+
"default": "./dist/react.cjs"
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
},
|
|
@@ -36,10 +37,11 @@
|
|
|
36
37
|
"dist"
|
|
37
38
|
],
|
|
38
39
|
"scripts": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
40
|
+
"build": "tsup src/index.ts src/react.tsx",
|
|
41
|
+
"prepack": "yarn build",
|
|
42
|
+
"publint": "attw --pack --profile node16 && publint",
|
|
43
|
+
"typecheck": "tsc -b tsconfig.json",
|
|
44
|
+
"test": "vitest"
|
|
43
45
|
},
|
|
44
46
|
"license": "MIT",
|
|
45
47
|
"publishConfig": {
|
|
@@ -48,7 +50,8 @@
|
|
|
48
50
|
},
|
|
49
51
|
"repository": {
|
|
50
52
|
"type": "git",
|
|
51
|
-
"url": "https://github.com/honojs/middleware.git"
|
|
53
|
+
"url": "git+https://github.com/honojs/middleware.git",
|
|
54
|
+
"directory": "packages/auth-js"
|
|
52
55
|
},
|
|
53
56
|
"homepage": "https://github.com/honojs/middleware",
|
|
54
57
|
"peerDependencies": {
|
|
@@ -57,16 +60,16 @@
|
|
|
57
60
|
"react": "^18 || ^19 || ^19.0.0-rc"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
63
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
60
64
|
"@auth/core": "^0.35.3",
|
|
61
65
|
"@types/react": "^18",
|
|
62
|
-
"
|
|
63
|
-
"jest": "^29.7.0",
|
|
66
|
+
"publint": "^0.3.9",
|
|
64
67
|
"react": "^18.2.0",
|
|
65
|
-
"tsup": "^8.0
|
|
66
|
-
"typescript": "^5.
|
|
67
|
-
"vitest": "^
|
|
68
|
+
"tsup": "^8.4.0",
|
|
69
|
+
"typescript": "^5.8.2",
|
|
70
|
+
"vitest": "^3.0.8"
|
|
68
71
|
},
|
|
69
72
|
"engines": {
|
|
70
73
|
"node": ">=18.4.0"
|
|
71
74
|
}
|
|
72
|
-
}
|
|
75
|
+
}
|