@hono/auth-js 1.0.5 → 1.0.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/dist/index.js +11 -10
- package/dist/index.mjs +11 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -28,6 +28,7 @@ __export(src_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
var import_core = require("@auth/core");
|
|
31
|
+
var import_adapter = require("hono/adapter");
|
|
31
32
|
var import_http_exception = require("hono/http-exception");
|
|
32
33
|
function reqWithEnvUrl(req, authUrl) {
|
|
33
34
|
if (authUrl) {
|
|
@@ -40,19 +41,19 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
40
41
|
return req;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
function setEnvDefaults(
|
|
44
|
-
config.secret ??=
|
|
44
|
+
function setEnvDefaults(env2, config) {
|
|
45
|
+
config.secret ??= env2.AUTH_SECRET;
|
|
45
46
|
config.basePath ??= "/api/auth";
|
|
46
47
|
config.trustHost = true;
|
|
47
|
-
config.redirectProxyUrl ??=
|
|
48
|
+
config.redirectProxyUrl ??= env2.AUTH_REDIRECT_PROXY_URL;
|
|
48
49
|
config.providers = config.providers.map((p) => {
|
|
49
50
|
const finalProvider = typeof p === "function" ? p({}) : p;
|
|
50
51
|
if (finalProvider.type === "oauth" || finalProvider.type === "oidc") {
|
|
51
52
|
const ID = finalProvider.id.toUpperCase();
|
|
52
|
-
finalProvider.clientId ??=
|
|
53
|
-
finalProvider.clientSecret ??=
|
|
53
|
+
finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
|
|
54
|
+
finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
|
|
54
55
|
if (finalProvider.type === "oidc") {
|
|
55
|
-
finalProvider.issuer ??=
|
|
56
|
+
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
return finalProvider;
|
|
@@ -60,8 +61,8 @@ function setEnvDefaults(env, config) {
|
|
|
60
61
|
}
|
|
61
62
|
async function getAuthUser(c) {
|
|
62
63
|
const config = c.get("authConfig");
|
|
63
|
-
setEnvDefaults(
|
|
64
|
-
const origin =
|
|
64
|
+
setEnvDefaults((0, import_adapter.env)(c), config);
|
|
65
|
+
const origin = (0, import_adapter.env)(c)["AUTH_URL"] ? new URL((0, import_adapter.env)(c)["AUTH_URL"]).origin : new URL(c.req.url).origin;
|
|
65
66
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
66
67
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
67
68
|
});
|
|
@@ -106,11 +107,11 @@ function initAuthConfig(cb) {
|
|
|
106
107
|
function authHandler() {
|
|
107
108
|
return async (c) => {
|
|
108
109
|
const config = c.get("authConfig");
|
|
109
|
-
setEnvDefaults(
|
|
110
|
+
setEnvDefaults((0, import_adapter.env)(c), config);
|
|
110
111
|
if (!config.secret) {
|
|
111
112
|
throw new import_http_exception.HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
112
113
|
}
|
|
113
|
-
const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw,
|
|
114
|
+
const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw, (0, import_adapter.env)(c)["AUTH_URL"]), config);
|
|
114
115
|
return new Response(res.body, res);
|
|
115
116
|
};
|
|
116
117
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Auth } from "@auth/core";
|
|
3
|
+
import { env } from "hono/adapter";
|
|
3
4
|
import { HTTPException } from "hono/http-exception";
|
|
4
5
|
function reqWithEnvUrl(req, authUrl) {
|
|
5
6
|
if (authUrl) {
|
|
@@ -12,19 +13,19 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
12
13
|
return req;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
function setEnvDefaults(
|
|
16
|
-
config.secret ??=
|
|
16
|
+
function setEnvDefaults(env2, config) {
|
|
17
|
+
config.secret ??= env2.AUTH_SECRET;
|
|
17
18
|
config.basePath ??= "/api/auth";
|
|
18
19
|
config.trustHost = true;
|
|
19
|
-
config.redirectProxyUrl ??=
|
|
20
|
+
config.redirectProxyUrl ??= env2.AUTH_REDIRECT_PROXY_URL;
|
|
20
21
|
config.providers = config.providers.map((p) => {
|
|
21
22
|
const finalProvider = typeof p === "function" ? p({}) : p;
|
|
22
23
|
if (finalProvider.type === "oauth" || finalProvider.type === "oidc") {
|
|
23
24
|
const ID = finalProvider.id.toUpperCase();
|
|
24
|
-
finalProvider.clientId ??=
|
|
25
|
-
finalProvider.clientSecret ??=
|
|
25
|
+
finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
|
|
26
|
+
finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
|
|
26
27
|
if (finalProvider.type === "oidc") {
|
|
27
|
-
finalProvider.issuer ??=
|
|
28
|
+
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
return finalProvider;
|
|
@@ -32,8 +33,8 @@ function setEnvDefaults(env, config) {
|
|
|
32
33
|
}
|
|
33
34
|
async function getAuthUser(c) {
|
|
34
35
|
const config = c.get("authConfig");
|
|
35
|
-
setEnvDefaults(c
|
|
36
|
-
const origin = c
|
|
36
|
+
setEnvDefaults(env(c), config);
|
|
37
|
+
const origin = env(c)["AUTH_URL"] ? new URL(env(c)["AUTH_URL"]).origin : new URL(c.req.url).origin;
|
|
37
38
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
38
39
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
39
40
|
});
|
|
@@ -78,11 +79,11 @@ function initAuthConfig(cb) {
|
|
|
78
79
|
function authHandler() {
|
|
79
80
|
return async (c) => {
|
|
80
81
|
const config = c.get("authConfig");
|
|
81
|
-
setEnvDefaults(c
|
|
82
|
+
setEnvDefaults(env(c), config);
|
|
82
83
|
if (!config.secret) {
|
|
83
84
|
throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
84
85
|
}
|
|
85
|
-
const res = await Auth(reqWithEnvUrl(c.req.raw, c
|
|
86
|
+
const res = await Auth(reqWithEnvUrl(c.req.raw, env(c)["AUTH_URL"]), config);
|
|
86
87
|
return new Response(res.body, res);
|
|
87
88
|
};
|
|
88
89
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/auth-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A third-party Auth js middleware for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"react": ">=18"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@auth/core": "^0.
|
|
60
|
+
"@auth/core": "^0.30.0",
|
|
61
61
|
"@types/react": "^18",
|
|
62
62
|
"hono": "^3.11.7",
|
|
63
63
|
"jest": "^29.7.0",
|