@kanjijs/auth 0.2.0-beta.55 → 0.2.0-beta.57
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 +27 -33
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8223,7 +8223,7 @@ async function Auth(request, config) {
|
|
|
8223
8223
|
}
|
|
8224
8224
|
}
|
|
8225
8225
|
|
|
8226
|
-
// ../../node_modules/.bun/hono@4.11.
|
|
8226
|
+
// ../../node_modules/.bun/hono@4.11.9/node_modules/hono/dist/helper/adapter/index.js
|
|
8227
8227
|
var env = (c3, runtime) => {
|
|
8228
8228
|
const global2 = globalThis;
|
|
8229
8229
|
const globalEnv = global2?.process?.env;
|
|
@@ -8273,7 +8273,7 @@ var checkUserAgentEquals = (platform) => {
|
|
|
8273
8273
|
return userAgent.startsWith(platform);
|
|
8274
8274
|
};
|
|
8275
8275
|
|
|
8276
|
-
// ../../node_modules/.bun/hono@4.11.
|
|
8276
|
+
// ../../node_modules/.bun/hono@4.11.9/node_modules/hono/dist/http-exception.js
|
|
8277
8277
|
var HTTPException = class extends Error {
|
|
8278
8278
|
res;
|
|
8279
8279
|
status;
|
|
@@ -8296,38 +8296,39 @@ var HTTPException = class extends Error {
|
|
|
8296
8296
|
}
|
|
8297
8297
|
};
|
|
8298
8298
|
|
|
8299
|
-
// ../../node_modules/.bun/@hono+auth-js@1.1.
|
|
8300
|
-
function setEnvDefaults2(
|
|
8301
|
-
config.secret ??=
|
|
8302
|
-
setEnvDefaults(
|
|
8299
|
+
// ../../node_modules/.bun/@hono+auth-js@1.1.1+34a86d3b96f06bef/node_modules/@hono/auth-js/dist/index.js
|
|
8300
|
+
function setEnvDefaults2(env$1, config) {
|
|
8301
|
+
config.secret ??= env$1.AUTH_SECRET;
|
|
8302
|
+
setEnvDefaults(env$1, config);
|
|
8303
8303
|
}
|
|
8304
8304
|
function reqWithEnvUrl(req, authUrl) {
|
|
8305
8305
|
if (authUrl) {
|
|
8306
8306
|
const reqUrlObj = new URL(req.url);
|
|
8307
8307
|
const authUrlObj = new URL(authUrl);
|
|
8308
|
-
const
|
|
8309
|
-
|
|
8310
|
-
|
|
8308
|
+
for (const prop of [
|
|
8309
|
+
"hostname",
|
|
8310
|
+
"protocol",
|
|
8311
|
+
"port",
|
|
8312
|
+
"password",
|
|
8313
|
+
"username"
|
|
8314
|
+
])
|
|
8315
|
+
if (authUrlObj[prop])
|
|
8311
8316
|
reqUrlObj[prop] = authUrlObj[prop];
|
|
8312
|
-
}
|
|
8313
|
-
}
|
|
8314
8317
|
return new Request(reqUrlObj.href, req);
|
|
8315
8318
|
}
|
|
8316
8319
|
const url = new URL(req.url);
|
|
8317
8320
|
const newReq = new Request(url.href, req);
|
|
8318
8321
|
const proto = newReq.headers.get("x-forwarded-proto");
|
|
8319
8322
|
const host = newReq.headers.get("x-forwarded-host") ?? newReq.headers.get("host");
|
|
8320
|
-
if (proto != null)
|
|
8323
|
+
if (proto != null)
|
|
8321
8324
|
url.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
8322
|
-
}
|
|
8323
8325
|
if (host != null) {
|
|
8324
8326
|
url.host = host;
|
|
8325
8327
|
const portMatch = host.match(/:(\d+)$/);
|
|
8326
|
-
if (portMatch)
|
|
8328
|
+
if (portMatch)
|
|
8327
8329
|
url.port = portMatch[1];
|
|
8328
|
-
|
|
8330
|
+
else
|
|
8329
8331
|
url.port = "";
|
|
8330
|
-
}
|
|
8331
8332
|
newReq.headers.delete("x-forwarded-host");
|
|
8332
8333
|
newReq.headers.delete("Host");
|
|
8333
8334
|
newReq.headers.set("Host", host);
|
|
@@ -8340,35 +8341,28 @@ async function getAuthUser(c3) {
|
|
|
8340
8341
|
setEnvDefaults2(ctxEnv, config);
|
|
8341
8342
|
const authReq = reqWithEnvUrl(c3.req.raw, ctxEnv.AUTH_URL);
|
|
8342
8343
|
const origin = new URL(authReq.url).origin;
|
|
8343
|
-
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
8344
|
-
headers: { cookie: c3.req.header("cookie") ?? "" }
|
|
8345
|
-
});
|
|
8344
|
+
const request = new Request(`${origin}${config.basePath}/session`, { headers: { cookie: c3.req.header("cookie") ?? "" } });
|
|
8346
8345
|
let authUser = {};
|
|
8347
|
-
|
|
8346
|
+
return (await (await Auth(request, {
|
|
8348
8347
|
...config,
|
|
8349
8348
|
callbacks: {
|
|
8350
8349
|
...config.callbacks,
|
|
8351
8350
|
async session(...args) {
|
|
8352
8351
|
authUser = args[0];
|
|
8353
|
-
const
|
|
8354
|
-
|
|
8355
|
-
|
|
8352
|
+
const session2 = await config.callbacks?.session?.(...args) ?? args[0].session;
|
|
8353
|
+
return {
|
|
8354
|
+
user: args[0].user ?? args[0].token,
|
|
8355
|
+
...session2
|
|
8356
|
+
};
|
|
8356
8357
|
}
|
|
8357
8358
|
}
|
|
8358
|
-
});
|
|
8359
|
-
const session2 = await response.json();
|
|
8360
|
-
return session2?.user ? authUser : null;
|
|
8359
|
+
})).json())?.user ? authUser : null;
|
|
8361
8360
|
}
|
|
8362
8361
|
function verifyAuth() {
|
|
8363
8362
|
return async (c3, next) => {
|
|
8364
8363
|
const authUser = await getAuthUser(c3);
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
const res = new Response("Unauthorized", {
|
|
8368
|
-
status: 401
|
|
8369
|
-
});
|
|
8370
|
-
throw new HTTPException(401, { res });
|
|
8371
|
-
}
|
|
8364
|
+
if (!(!!authUser?.token || !!authUser?.user))
|
|
8365
|
+
throw new HTTPException(401, { res: new Response("Unauthorized", { status: 401 }) });
|
|
8372
8366
|
c3.set("authUser", authUser);
|
|
8373
8367
|
await next();
|
|
8374
8368
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/auth",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.57",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"hono": "^4.0.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@kanjijs/core": "^0.2.0-beta.
|
|
21
|
+
"@kanjijs/core": "^0.2.0-beta.57"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.0.0",
|