@hono/auth-js 1.0.3 → 1.0.5

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.d.mts CHANGED
@@ -23,9 +23,10 @@ type AuthUser = {
23
23
  interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
24
24
  }
25
25
  type ConfigHandler = (c: Context) => AuthConfig;
26
+ declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
26
27
  declare function getAuthUser(c: Context): Promise<AuthUser | null>;
27
28
  declare function verifyAuth(): MiddlewareHandler;
28
29
  declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
29
30
  declare function authHandler(): MiddlewareHandler;
30
31
 
31
- export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, verifyAuth };
32
+ export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, verifyAuth };
package/dist/index.d.ts CHANGED
@@ -23,9 +23,10 @@ type AuthUser = {
23
23
  interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
24
24
  }
25
25
  type ConfigHandler = (c: Context) => AuthConfig;
26
+ declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
26
27
  declare function getAuthUser(c: Context): Promise<AuthUser | null>;
27
28
  declare function verifyAuth(): MiddlewareHandler;
28
29
  declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
29
30
  declare function authHandler(): MiddlewareHandler;
30
31
 
31
- export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, verifyAuth };
32
+ export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, verifyAuth };
package/dist/index.js CHANGED
@@ -23,13 +23,22 @@ __export(src_exports, {
23
23
  authHandler: () => authHandler,
24
24
  getAuthUser: () => getAuthUser,
25
25
  initAuthConfig: () => initAuthConfig,
26
+ reqWithEnvUrl: () => reqWithEnvUrl,
26
27
  verifyAuth: () => verifyAuth
27
28
  });
28
29
  module.exports = __toCommonJS(src_exports);
29
30
  var import_core = require("@auth/core");
30
31
  var import_http_exception = require("hono/http-exception");
31
32
  function reqWithEnvUrl(req, authUrl) {
32
- return authUrl ? new Request(new URL(req.url, authUrl).href, req) : req;
33
+ if (authUrl) {
34
+ const reqUrlObj = new URL(req.url);
35
+ const authUrlObj = new URL(authUrl);
36
+ const props = ["hostname", "protocol", "port", "password", "username"];
37
+ props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
38
+ return new Request(reqUrlObj.href, req);
39
+ } else {
40
+ return req;
41
+ }
33
42
  }
34
43
  function setEnvDefaults(env, config) {
35
44
  config.secret ??= env.AUTH_SECRET;
@@ -52,7 +61,7 @@ function setEnvDefaults(env, config) {
52
61
  async function getAuthUser(c) {
53
62
  const config = c.get("authConfig");
54
63
  setEnvDefaults(c.env, config);
55
- const origin = new URL(c.req.url, c.env.AUTH_URL).origin;
64
+ const origin = c.env.AUTH_URL ? new URL(c.env.AUTH_URL).origin : new URL(c.req.url).origin;
56
65
  const request = new Request(`${origin}${config.basePath}/session`, {
57
66
  headers: { cookie: c.req.header("cookie") ?? "" }
58
67
  });
@@ -110,5 +119,6 @@ function authHandler() {
110
119
  authHandler,
111
120
  getAuthUser,
112
121
  initAuthConfig,
122
+ reqWithEnvUrl,
113
123
  verifyAuth
114
124
  });
package/dist/index.mjs CHANGED
@@ -2,7 +2,15 @@
2
2
  import { Auth } from "@auth/core";
3
3
  import { HTTPException } from "hono/http-exception";
4
4
  function reqWithEnvUrl(req, authUrl) {
5
- return authUrl ? new Request(new URL(req.url, authUrl).href, req) : req;
5
+ if (authUrl) {
6
+ const reqUrlObj = new URL(req.url);
7
+ const authUrlObj = new URL(authUrl);
8
+ const props = ["hostname", "protocol", "port", "password", "username"];
9
+ props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
10
+ return new Request(reqUrlObj.href, req);
11
+ } else {
12
+ return req;
13
+ }
6
14
  }
7
15
  function setEnvDefaults(env, config) {
8
16
  config.secret ??= env.AUTH_SECRET;
@@ -25,7 +33,7 @@ function setEnvDefaults(env, config) {
25
33
  async function getAuthUser(c) {
26
34
  const config = c.get("authConfig");
27
35
  setEnvDefaults(c.env, config);
28
- const origin = new URL(c.req.url, c.env.AUTH_URL).origin;
36
+ const origin = c.env.AUTH_URL ? new URL(c.env.AUTH_URL).origin : new URL(c.req.url).origin;
29
37
  const request = new Request(`${origin}${config.basePath}/session`, {
30
38
  headers: { cookie: c.req.header("cookie") ?? "" }
31
39
  });
@@ -82,5 +90,6 @@ export {
82
90
  authHandler,
83
91
  getAuthUser,
84
92
  initAuthConfig,
93
+ reqWithEnvUrl,
85
94
  verifyAuth
86
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/auth-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A third-party Auth js middleware for Hono",
5
5
  "main": "dist/index.js",
6
6
  "exports": {