@hono/auth-js 1.0.5 → 1.0.7

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
@@ -11,6 +11,7 @@ declare module 'hono' {
11
11
  }
12
12
  }
13
13
  type AuthEnv = {
14
+ AUTH_URL?: string;
14
15
  AUTH_SECRET: string;
15
16
  AUTH_REDIRECT_PROXY_URL?: string;
16
17
  [key: string]: string | undefined;
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ declare module 'hono' {
11
11
  }
12
12
  }
13
13
  type AuthEnv = {
14
+ AUTH_URL?: string;
14
15
  AUTH_SECRET: string;
15
16
  AUTH_REDIRECT_PROXY_URL?: string;
16
17
  [key: string]: string | undefined;
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(env, config) {
44
- config.secret ??= env.AUTH_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 ??= env.AUTH_REDIRECT_PROXY_URL;
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 ??= env[`AUTH_${ID}_ID`];
53
- finalProvider.clientSecret ??= env[`AUTH_${ID}_SECRET`];
53
+ finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
54
+ finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
54
55
  if (finalProvider.type === "oidc") {
55
- finalProvider.issuer ??= env[`AUTH_${ID}_ISSUER`];
56
+ finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
56
57
  }
57
58
  }
58
59
  return finalProvider;
@@ -60,8 +61,9 @@ function setEnvDefaults(env, config) {
60
61
  }
61
62
  async function getAuthUser(c) {
62
63
  const config = c.get("authConfig");
63
- setEnvDefaults(c.env, config);
64
- const origin = c.env.AUTH_URL ? new URL(c.env.AUTH_URL).origin : new URL(c.req.url).origin;
64
+ let ctxEnv = (0, import_adapter.env)(c);
65
+ setEnvDefaults(ctxEnv, config);
66
+ const origin = ctxEnv.AUTH_URL ? new URL(ctxEnv.AUTH_URL).origin : new URL(c.req.url).origin;
65
67
  const request = new Request(`${origin}${config.basePath}/session`, {
66
68
  headers: { cookie: c.req.header("cookie") ?? "" }
67
69
  });
@@ -106,11 +108,12 @@ function initAuthConfig(cb) {
106
108
  function authHandler() {
107
109
  return async (c) => {
108
110
  const config = c.get("authConfig");
109
- setEnvDefaults(c.env, config);
111
+ let ctxEnv = (0, import_adapter.env)(c);
112
+ setEnvDefaults(ctxEnv, config);
110
113
  if (!config.secret) {
111
114
  throw new import_http_exception.HTTPException(500, { message: "Missing AUTH_SECRET" });
112
115
  }
113
- const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw, c.env.AUTH_URL), config);
116
+ const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config);
114
117
  return new Response(res.body, res);
115
118
  };
116
119
  }
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(env, config) {
16
- config.secret ??= env.AUTH_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 ??= env.AUTH_REDIRECT_PROXY_URL;
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 ??= env[`AUTH_${ID}_ID`];
25
- finalProvider.clientSecret ??= env[`AUTH_${ID}_SECRET`];
25
+ finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
26
+ finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
26
27
  if (finalProvider.type === "oidc") {
27
- finalProvider.issuer ??= env[`AUTH_${ID}_ISSUER`];
28
+ finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
28
29
  }
29
30
  }
30
31
  return finalProvider;
@@ -32,8 +33,9 @@ function setEnvDefaults(env, config) {
32
33
  }
33
34
  async function getAuthUser(c) {
34
35
  const config = c.get("authConfig");
35
- setEnvDefaults(c.env, config);
36
- const origin = c.env.AUTH_URL ? new URL(c.env.AUTH_URL).origin : new URL(c.req.url).origin;
36
+ let ctxEnv = env(c);
37
+ setEnvDefaults(ctxEnv, config);
38
+ const origin = ctxEnv.AUTH_URL ? new URL(ctxEnv.AUTH_URL).origin : new URL(c.req.url).origin;
37
39
  const request = new Request(`${origin}${config.basePath}/session`, {
38
40
  headers: { cookie: c.req.header("cookie") ?? "" }
39
41
  });
@@ -78,11 +80,12 @@ function initAuthConfig(cb) {
78
80
  function authHandler() {
79
81
  return async (c) => {
80
82
  const config = c.get("authConfig");
81
- setEnvDefaults(c.env, config);
83
+ let ctxEnv = env(c);
84
+ setEnvDefaults(ctxEnv, config);
82
85
  if (!config.secret) {
83
86
  throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
84
87
  }
85
- const res = await Auth(reqWithEnvUrl(c.req.raw, c.env.AUTH_URL), config);
88
+ const res = await Auth(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config);
86
89
  return new Response(res.body, res);
87
90
  };
88
91
  }
package/dist/react.d.mts CHANGED
@@ -132,13 +132,6 @@ interface GetSessionParams {
132
132
  broadcast?: boolean;
133
133
  }
134
134
  declare function getSession(params?: GetSessionParams): Promise<Session | null>;
135
- /**
136
- * Returns the current Cross-Site Request Forgery Token (CSRF Token)
137
- * required to make requests that changes state. (e.g. signing in or out, or updating the session).
138
- *
139
- * [CSRF Prevention: Double Submit Cookie](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie)
140
- * @internal
141
- */
142
135
  declare function getCsrfToken(): Promise<string>;
143
136
  type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
144
137
  declare function getProviders(): Promise<ProvidersType | null>;
package/dist/react.d.ts CHANGED
@@ -132,13 +132,6 @@ interface GetSessionParams {
132
132
  broadcast?: boolean;
133
133
  }
134
134
  declare function getSession(params?: GetSessionParams): Promise<Session | null>;
135
- /**
136
- * Returns the current Cross-Site Request Forgery Token (CSRF Token)
137
- * required to make requests that changes state. (e.g. signing in or out, or updating the session).
138
- *
139
- * [CSRF Prevention: Double Submit Cookie](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie)
140
- * @internal
141
- */
142
135
  declare function getCsrfToken(): Promise<string>;
143
136
  type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
144
137
  declare function getProviders(): Promise<ProvidersType | null>;
package/dist/react.js CHANGED
@@ -115,8 +115,8 @@ function parseUrl(url) {
115
115
  var AuthConfigManager = class _AuthConfigManager {
116
116
  static instance = null;
117
117
  _config = {
118
- baseUrl: parseUrl(window.location.origin).origin,
119
- basePath: parseUrl(window.location.origin).path,
118
+ baseUrl: typeof window !== "undefined" ? parseUrl(window.location.origin).origin : "",
119
+ basePath: typeof window !== "undefined" ? parseUrl(window.location.origin).path : "/api/auth",
120
120
  credentials: "same-origin",
121
121
  _lastSync: 0,
122
122
  _session: void 0,
package/dist/react.mjs CHANGED
@@ -73,8 +73,8 @@ function parseUrl(url) {
73
73
  var AuthConfigManager = class _AuthConfigManager {
74
74
  static instance = null;
75
75
  _config = {
76
- baseUrl: parseUrl(window.location.origin).origin,
77
- basePath: parseUrl(window.location.origin).path,
76
+ baseUrl: typeof window !== "undefined" ? parseUrl(window.location.origin).origin : "",
77
+ basePath: typeof window !== "undefined" ? parseUrl(window.location.origin).path : "/api/auth",
78
78
  credentials: "same-origin",
79
79
  _lastSync: 0,
80
80
  _session: void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/auth-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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.24.0",
60
+ "@auth/core": "^0.30.0",
61
61
  "@types/react": "^18",
62
62
  "hono": "^3.11.7",
63
63
  "jest": "^29.7.0",