@aura-stack/auth 0.1.0 → 0.2.0-rc.1

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.
Files changed (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
@@ -34,60 +34,71 @@ __export(userinfo_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(userinfo_exports);
36
36
 
37
+ // src/request.ts
38
+ var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
39
+ const controller = new AbortController();
40
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
41
+ const response = await fetch(url, {
42
+ ...options2,
43
+ signal: controller.signal
44
+ }).finally(() => clearTimeout(timeoutId));
45
+ return response;
46
+ };
47
+
37
48
  // src/secure.ts
38
- var import_node_crypto = __toESM(require("crypto"), 1);
49
+ var import_crypto = __toESM(require("crypto"), 1);
39
50
 
40
51
  // src/utils.ts
41
52
  var import_router = require("@aura-stack/router");
42
53
 
43
- // src/error.ts
44
- var AuthError = class extends Error {
45
- constructor(type, message) {
46
- super(message);
47
- this.type = type;
48
- this.name = "AuthError";
54
+ // src/errors.ts
55
+ var OAuthProtocolError = class extends Error {
56
+ type = "OAUTH_PROTOCOL_ERROR";
57
+ error;
58
+ errorURI;
59
+ constructor(error, description, errorURI, options2) {
60
+ super(description, options2);
61
+ this.error = error;
62
+ this.errorURI = errorURI;
63
+ this.name = new.target.name;
64
+ Error.captureStackTrace(this, new.target);
49
65
  }
50
66
  };
51
- var isAuthError = (error) => {
52
- return error instanceof AuthError;
67
+ var isNativeError = (error) => {
68
+ return error instanceof Error;
53
69
  };
54
- var throwAuthError = (error, message) => {
55
- if (error instanceof Error) {
56
- if (isAuthError(error)) {
57
- throw error;
58
- }
59
- throw new AuthError("invalid_request", error.message ?? message);
60
- }
70
+ var isOAuthProtocolError = (error) => {
71
+ return error instanceof OAuthProtocolError;
61
72
  };
62
73
 
63
74
  // src/secure.ts
64
75
  var generateSecure = (length = 32) => {
65
- return import_node_crypto.default.randomBytes(length).toString("base64url");
76
+ return import_crypto.default.randomBytes(length).toString("base64url");
66
77
  };
67
78
 
68
79
  // src/schemas.ts
69
- var import_v4 = require("zod/v4");
70
- var OAuthProviderConfigSchema = (0, import_v4.object)({
71
- authorizeURL: (0, import_v4.url)(),
72
- accessToken: (0, import_v4.url)(),
73
- scope: (0, import_v4.string)().optional(),
74
- userInfo: (0, import_v4.url)(),
75
- responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
76
- clientId: (0, import_v4.string)(),
77
- clientSecret: (0, import_v4.string)()
80
+ var import_zod = require("zod");
81
+ var OAuthProviderConfigSchema = (0, import_zod.object)({
82
+ authorizeURL: (0, import_zod.string)().url(),
83
+ accessToken: (0, import_zod.string)().url(),
84
+ scope: (0, import_zod.string)().optional(),
85
+ userInfo: (0, import_zod.string)().url(),
86
+ responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
87
+ clientId: (0, import_zod.string)(),
88
+ clientSecret: (0, import_zod.string)()
78
89
  });
79
90
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
80
- redirectURI: (0, import_v4.string)(),
81
- state: (0, import_v4.string)(),
82
- codeChallenge: (0, import_v4.string)(),
83
- codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
91
+ redirectURI: (0, import_zod.string)(),
92
+ state: (0, import_zod.string)(),
93
+ codeChallenge: (0, import_zod.string)(),
94
+ codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
84
95
  });
85
- var OAuthAuthorizationResponse = (0, import_v4.object)({
86
- state: (0, import_v4.string)(),
87
- code: (0, import_v4.string)()
96
+ var OAuthAuthorizationResponse = (0, import_zod.object)({
97
+ state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
98
+ code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
88
99
  });
89
- var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
90
- error: (0, import_v4.enum)([
100
+ var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
101
+ error: (0, import_zod.enum)([
91
102
  "invalid_request",
92
103
  "unauthorized_client",
93
104
  "access_denied",
@@ -96,24 +107,24 @@ var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
96
107
  "server_error",
97
108
  "temporarily_unavailable"
98
109
  ]),
99
- error_description: (0, import_v4.string)().optional(),
100
- error_uri: (0, import_v4.string)().optional(),
101
- state: (0, import_v4.string)()
110
+ error_description: (0, import_zod.string)().optional(),
111
+ error_uri: (0, import_zod.string)().optional(),
112
+ state: (0, import_zod.string)()
102
113
  });
103
114
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
104
- redirectURI: (0, import_v4.string)(),
105
- code: (0, import_v4.string)(),
106
- codeVerifier: (0, import_v4.string)().min(43).max(128)
115
+ redirectURI: (0, import_zod.string)(),
116
+ code: (0, import_zod.string)(),
117
+ codeVerifier: (0, import_zod.string)().min(43).max(128)
107
118
  });
108
- var OAuthAccessTokenResponse = (0, import_v4.object)({
109
- access_token: (0, import_v4.string)(),
110
- token_type: (0, import_v4.string)(),
111
- expires_in: (0, import_v4.number)().optional(),
112
- refresh_token: (0, import_v4.string)().optional(),
113
- scope: (0, import_v4.string)().optional()
119
+ var OAuthAccessTokenResponse = (0, import_zod.object)({
120
+ access_token: (0, import_zod.string)(),
121
+ token_type: (0, import_zod.string)().optional(),
122
+ expires_in: (0, import_zod.number)().optional(),
123
+ refresh_token: (0, import_zod.string)().optional(),
124
+ scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
114
125
  });
115
- var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
116
- error: (0, import_v4.enum)([
126
+ var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
127
+ error: (0, import_zod.enum)([
117
128
  "invalid_request",
118
129
  "invalid_client",
119
130
  "invalid_grant",
@@ -121,12 +132,16 @@ var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
121
132
  "unsupported_grant_type",
122
133
  "invalid_scope"
123
134
  ]),
124
- error_description: (0, import_v4.string)().optional(),
125
- error_uri: (0, import_v4.string)().optional()
135
+ error_description: (0, import_zod.string)().optional(),
136
+ error_uri: (0, import_zod.string)().optional()
126
137
  });
127
- var OAuthErrorResponse = (0, import_v4.object)({
128
- error: (0, import_v4.string)(),
129
- error_description: (0, import_v4.string)().optional()
138
+ var OAuthErrorResponse = (0, import_zod.object)({
139
+ error: (0, import_zod.string)(),
140
+ error_description: (0, import_zod.string)().optional()
141
+ });
142
+ var OAuthEnvSchema = (0, import_zod.object)({
143
+ clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
144
+ clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
130
145
  });
131
146
 
132
147
  // src/actions/callback/userinfo.ts
@@ -142,7 +157,7 @@ var getDefaultUserInfo = (profile) => {
142
157
  var getUserInfo = async (oauthConfig, accessToken) => {
143
158
  const userinfoEndpoint = oauthConfig.userInfo;
144
159
  try {
145
- const response = await fetch(userinfoEndpoint, {
160
+ const response = await fetchAsync(userinfoEndpoint, {
146
161
  method: "GET",
147
162
  headers: {
148
163
  Accept: "application/json",
@@ -152,11 +167,20 @@ var getUserInfo = async (oauthConfig, accessToken) => {
152
167
  const json = await response.json();
153
168
  const { success, data } = OAuthErrorResponse.safeParse(json);
154
169
  if (success) {
155
- throw new AuthError(data.error, data?.error_description ?? "An error occurred while fetching user information.");
170
+ throw new OAuthProtocolError(
171
+ data.error,
172
+ data?.error_description ?? "An error occurred while fetching user information."
173
+ );
156
174
  }
157
175
  return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
158
176
  } catch (error) {
159
- throw throwAuthError(error, "Failed to retrieve userinfo");
177
+ if (isOAuthProtocolError(error)) {
178
+ throw error;
179
+ }
180
+ if (isNativeError(error)) {
181
+ throw new OAuthProtocolError("invalid_request", error.message, "", { cause: error });
182
+ }
183
+ throw new OAuthProtocolError("invalid_request", "Failed to fetch user information.", "", { cause: error });
160
184
  }
161
185
  };
162
186
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,9 +1,9 @@
1
- import { f as OAuthProviderCredentials, U as User } from '../../index-DpfbvTZ_.js';
2
- import 'zod/v4';
3
- import '@aura-stack/jose/jose';
1
+ import { h as OAuthProviderCredentials, U as User } from '../../index-DkaLJFn8.js';
2
+ import 'zod';
4
3
  import '../../schemas.js';
5
- import 'zod/v4/core';
6
- import 'cookie';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose';
6
+ import '@aura-stack/jose/jose';
7
7
  import '../../@types/utility.js';
8
8
 
9
9
  /**
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  getUserInfo
3
- } from "../../chunk-RLT4RFKV.js";
4
- import "../../chunk-GZU3RBTB.js";
5
- import "../../chunk-256KIVJL.js";
6
- import "../../chunk-FJUDBLCP.js";
7
- import "../../chunk-HMRKN75I.js";
3
+ } from "../../chunk-IVET23KF.js";
4
+ import "../../chunk-N2APGLXA.js";
5
+ import "../../chunk-CXLATHS5.js";
6
+ import "../../chunk-EIL2FPSS.js";
7
+ import "../../chunk-RRLIF4PQ.js";
8
+ import "../../chunk-ZNCZVF6U.js";
9
+ import "../../chunk-YRCB5FLE.js";
8
10
  export {
9
11
  getUserInfo
10
12
  };
@@ -36,23 +36,26 @@ module.exports = __toCommonJS(csrfToken_exports);
36
36
  var import_router2 = require("@aura-stack/router");
37
37
 
38
38
  // src/secure.ts
39
- var import_node_crypto = __toESM(require("crypto"), 1);
39
+ var import_crypto = __toESM(require("crypto"), 1);
40
40
 
41
41
  // src/utils.ts
42
42
  var import_router = require("@aura-stack/router");
43
43
 
44
- // src/error.ts
45
- var AuthError = class extends Error {
46
- constructor(type, message) {
47
- super(message);
48
- this.type = type;
49
- this.name = "AuthError";
44
+ // src/errors.ts
45
+ var AuthInternalError = class extends Error {
46
+ type = "AUTH_INTERNAL_ERROR";
47
+ code;
48
+ constructor(code, message, options) {
49
+ super(message, options);
50
+ this.code = code;
51
+ this.name = new.target.name;
52
+ Error.captureStackTrace(this, new.target);
50
53
  }
51
54
  };
52
55
 
53
56
  // src/secure.ts
54
57
  var generateSecure = (length = 32) => {
55
- return import_node_crypto.default.randomBytes(length).toString("base64url");
58
+ return import_crypto.default.randomBytes(length).toString("base64url");
56
59
  };
57
60
  var createCSRF = async (jose, csrfCookie) => {
58
61
  try {
@@ -77,128 +80,56 @@ var cacheControl = {
77
80
  };
78
81
 
79
82
  // src/cookie.ts
80
- var import_cookie = require("cookie");
81
-
82
- // src/assert.ts
83
- var isRequest = (value) => {
84
- return typeof Request !== "undefined" && value instanceof Request;
85
- };
86
-
87
- // src/cookie.ts
88
- var import_cookie2 = require("cookie");
89
- var COOKIE_NAME = "aura-auth";
83
+ var import_cookie = require("@aura-stack/router/cookie");
90
84
  var defaultCookieOptions = {
91
85
  httpOnly: true,
92
86
  sameSite: "lax",
93
87
  path: "/",
94
88
  maxAge: 60 * 60 * 24 * 15
95
89
  };
96
- var defaultStandardCookieConfig = {
97
- secure: false,
90
+ var oauthCookieOptions = {
98
91
  httpOnly: true,
99
- prefix: ""
100
- };
101
- var defaultSecureCookieConfig = {
102
- secure: true,
103
- prefix: "__Secure-"
92
+ maxAge: 5 * 60,
93
+ sameSite: "lax",
94
+ expires: new Date(Date.now() + 5 * 60 * 1e3)
104
95
  };
105
- var defaultHostCookieConfig = {
106
- secure: true,
107
- prefix: "__Host-",
108
- path: "/",
109
- domain: void 0
96
+ var setCookie = (cookieName, value, options) => {
97
+ return (0, import_cookie.serialize)(cookieName, value, options);
110
98
  };
111
- var expiredCookieOptions = {
99
+ var expiredCookieAttributes = {
112
100
  ...defaultCookieOptions,
113
101
  expires: /* @__PURE__ */ new Date(0),
114
102
  maxAge: 0
115
103
  };
116
- var defineDefaultCookieOptions = (options) => {
117
- return {
118
- name: options?.name ?? COOKIE_NAME,
119
- prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
120
- ...defaultCookieOptions,
121
- ...options
122
- };
123
- };
124
- var setCookie = (cookieName, value, options) => {
125
- const { prefix, name } = defineDefaultCookieOptions(options);
126
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
127
- return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
128
- ...defaultCookieOptions,
129
- ...options
130
- });
131
- };
132
- var getCookie = (petition, cookie, options, optional = false) => {
133
- const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
104
+ var getCookie = (request, cookieName) => {
105
+ const cookies = request.headers.get("Cookie");
134
106
  if (!cookies) {
135
- if (optional) {
136
- return "";
137
- }
138
- throw new AuthError("invalid_request", "No cookies found. There is no active session");
107
+ throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
139
108
  }
140
- const { name, prefix } = defineDefaultCookieOptions(options);
141
- const parsedCookies = (0, import_cookie.parse)(cookies);
142
- const value = parsedCookies[`${prefix}${name}.${cookie}`];
143
- if (value === void 0) {
144
- if (optional) {
145
- return "";
146
- }
147
- throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
109
+ const value = (0, import_cookie.parse)(cookies)[cookieName];
110
+ if (!value) {
111
+ throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
148
112
  }
149
113
  return value;
150
114
  };
151
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
152
- const name = cookieOptions.name ?? COOKIE_NAME;
153
- const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
154
- if (!cookieOptions.options?.httpOnly) {
155
- console.warn(
156
- "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
157
- );
158
- }
159
- if (cookieOptions.options?.domain === "*") {
160
- console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
161
- }
162
- if (!isSecure) {
163
- const options = cookieOptions.options;
164
- if (options?.secure) {
165
- console.warn(
166
- "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
167
- );
168
- }
169
- if (options?.sameSite == "none") {
170
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
171
- }
172
- if (process.env.NODE_ENV === "production") {
173
- console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
174
- }
175
- return {
176
- ...defaultCookieOptions,
177
- ...cookieOptions.options,
178
- sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
179
- ...defaultStandardCookieConfig,
180
- name
181
- };
182
- }
183
- return cookieOptions.strategy === "host" ? {
184
- ...defaultCookieOptions,
185
- ...cookieOptions.options,
186
- ...defaultHostCookieConfig,
187
- name
188
- } : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
189
- };
190
115
 
191
116
  // src/actions/csrfToken/csrfToken.ts
117
+ var getCSRFToken = (request, cookieName) => {
118
+ try {
119
+ return getCookie(request, cookieName);
120
+ } catch {
121
+ return void 0;
122
+ }
123
+ };
192
124
  var csrfTokenAction = (0, import_router2.createEndpoint)("GET", "/csrfToken", async (ctx) => {
193
125
  const {
194
126
  request,
195
- context: { cookies, jose, trustedProxyHeaders }
127
+ context: { jose, cookies }
196
128
  } = ctx;
197
- const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders);
198
- const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true);
199
- const csrfToken = await createCSRF(jose, existingCSRFToken);
129
+ const token = getCSRFToken(request, cookies.csrfToken.name);
130
+ const csrfToken = await createCSRF(jose, token);
200
131
  const headers = new Headers(cacheControl);
201
- headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions));
132
+ headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
202
133
  return Response.json({ csrfToken }, { headers });
203
134
  });
204
135
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  csrfTokenAction
3
- } from "../../chunk-SMQO5WD7.js";
4
- import "../../chunk-ZV4BH47P.js";
5
- import "../../chunk-6SM22VVJ.js";
3
+ } from "../../chunk-HT4YLL7N.js";
4
+ import "../../chunk-W6LG7BFW.js";
6
5
  import "../../chunk-STHEPPUZ.js";
7
- import "../../chunk-GZU3RBTB.js";
8
- import "../../chunk-256KIVJL.js";
9
- import "../../chunk-FJUDBLCP.js";
6
+ import "../../chunk-N2APGLXA.js";
7
+ import "../../chunk-CXLATHS5.js";
8
+ import "../../chunk-EIL2FPSS.js";
9
+ import "../../chunk-RRLIF4PQ.js";
10
10
  export {
11
11
  csrfTokenAction
12
12
  };