propro-utils 1.7.0 → 1.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -99,7 +99,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
99
99
  new Date(tokens.access.expires).getTime() - currentDateTime.getTime();
100
100
 
101
101
  // Domain configuration
102
- let domain;
103
102
  let isSecureConnection = false;
104
103
  try {
105
104
  // Handle URLs that don't include the protocol
@@ -113,23 +112,9 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
113
112
  }
114
113
 
115
114
  const urlObj = new URL(processedAppUrl);
116
- domain = urlObj.hostname;
117
115
  isSecureConnection = urlObj.protocol === "https:";
118
116
 
119
- if (domain?.includes("mapmap.app")) {
120
- domain = ".mapmap.app";
121
- }
122
- if (domain?.includes("localhost")) {
123
- domain = undefined;
124
- isSecureConnection = false;
125
- }
126
- if (domain?.includes("propro.so")) {
127
- // Set root domain for all propro.so subdomains
128
- domain = ".propro.so";
129
- }
130
-
131
117
  console.log("Cookie configuration:", {
132
- domain,
133
118
  isSecure: isSecureConnection,
134
119
  protocol: urlObj.protocol,
135
120
  originalUrl: appUrl,
@@ -138,22 +123,14 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
138
123
  });
139
124
  } catch (error) {
140
125
  console.error("Invalid appUrl:", { error, appUrl });
141
- domain = undefined;
142
126
  isSecureConnection = false;
143
127
  }
144
128
 
145
- // Determine if we're in a local development environment
146
- const isLocalhost =
147
- !domain || domain === "localhost" || domain.includes("localhost");
148
-
149
- // Base attributes that work across domains
129
+ // Base cookie attributes without domain specification
150
130
  const commonAttributes = {
151
- secure: true, // Always use secure in production
152
- sameSite: "None", // Required for cross-domain
153
- domain: domain,
131
+ secure: true,
132
+ sameSite: "None",
154
133
  path: "/",
155
- httpOnly: false,
156
- expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
157
134
  };
158
135
 
159
136
  const httpOnlyCookies = {
@@ -161,17 +138,11 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
161
138
  value: tokens.refresh.token,
162
139
  maxAge: refreshMaxAge,
163
140
  httpOnly: true,
164
- secure: true,
165
- sameSite: "None",
166
- domain: domain,
167
141
  },
168
142
  "x-access-token": {
169
143
  value: tokens.access.token,
170
144
  maxAge: accessMaxAge,
171
145
  httpOnly: true,
172
- secure: true,
173
- sameSite: "None",
174
- domain: domain,
175
146
  },
176
147
  };
177
148
 
@@ -184,60 +155,40 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
184
155
  value: safeStringify(sanitizedUser),
185
156
  maxAge: refreshMaxAge,
186
157
  httpOnly: false,
187
- secure: true,
188
- sameSite: "None",
189
- domain: domain,
190
158
  },
191
159
  account: {
192
160
  value: safeStringify(sanitizedAccount),
193
161
  maxAge: refreshMaxAge,
194
162
  httpOnly: false,
195
- secure: true,
196
- sameSite: "None",
197
- domain: domain,
198
163
  },
199
164
  has_account_token: {
200
165
  value: JSON.stringify({ value: "true", expires: accessMaxAge }),
201
166
  maxAge: accessMaxAge,
202
167
  httpOnly: false,
203
- secure: true,
204
- sameSite: "None",
205
- domain: domain,
206
168
  },
207
169
  };
208
170
 
209
171
  try {
210
- // Set each cookie individually with full attributes
172
+ // Set each cookie individually
211
173
  Object.entries({ ...httpOnlyCookies, ...regularCookies }).forEach(
212
174
  ([name, config]) => {
213
- // Ensure all required attributes are explicitly set
214
175
  const cookieConfig = {
215
176
  ...commonAttributes,
216
177
  ...config,
217
- domain: domain, // Explicitly set domain for each cookie
218
178
  };
219
179
 
220
180
  res.cookie(name, config.value, cookieConfig);
221
-
222
- // Also try setting without domain for root domain
223
- if (domain === ".propro.so") {
224
- const rootConfig = { ...cookieConfig };
225
- delete rootConfig.domain;
226
- res.cookie(name, config.value, rootConfig);
227
- }
228
181
  }
229
182
  );
230
183
 
231
- // Skip extension cookie setting if not in extension context
184
+ // Handle extension cookies if in extension context
232
185
  try {
233
186
  const extensionCookiePromises = Object.entries({
234
187
  ...httpOnlyCookies,
235
188
  ...regularCookies,
236
189
  }).map(([name, config]) => {
237
190
  return setChromeExtensionCookie({
238
- url: `https://${
239
- domain?.startsWith(".") ? domain.slice(1) : domain || "propro.so"
240
- }`,
191
+ url: processedAppUrl,
241
192
  name,
242
193
  value: config.value,
243
194
  secure: true,
@@ -245,7 +196,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
245
196
  sameSite: "no_restriction",
246
197
  path: "/",
247
198
  expirationDate: Math.floor((Date.now() + config.maxAge) / 1000),
248
- domain: domain,
249
199
  });
250
200
  });
251
201
 
@@ -257,7 +207,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
257
207
  }
258
208
 
259
209
  console.log("Auth cookies set successfully", {
260
- domain,
261
210
  sameSite: commonAttributes.sameSite,
262
211
  cookieNames: [
263
212
  ...Object.keys(httpOnlyCookies),
@@ -277,7 +226,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
277
226
  * Clears cookies from both web and extension contexts
278
227
  */
279
228
  const clearAuthCookies = async (res, appUrl) => {
280
- let domain;
281
229
  let isSecureConnection = false;
282
230
  try {
283
231
  // Handle URLs that don't include the protocol
@@ -291,22 +239,9 @@ const clearAuthCookies = async (res, appUrl) => {
291
239
  }
292
240
 
293
241
  const urlObj = new URL(processedAppUrl);
294
- domain = urlObj.hostname;
295
242
  isSecureConnection = urlObj.protocol === "https:";
296
243
 
297
- if (domain?.includes("mapmap.app")) {
298
- domain = ".mapmap.app";
299
- }
300
- if (domain?.includes("localhost")) {
301
- domain = undefined;
302
- isSecureConnection = false;
303
- }
304
- if (domain?.includes("propro.so")) {
305
- domain = ".propro.so";
306
- }
307
-
308
244
  console.log("Clear cookies configuration:", {
309
- domain,
310
245
  isSecure: isSecureConnection,
311
246
  protocol: urlObj.protocol,
312
247
  originalUrl: appUrl,
@@ -315,16 +250,13 @@ const clearAuthCookies = async (res, appUrl) => {
315
250
  });
316
251
  } catch (error) {
317
252
  console.error("Invalid appUrl:", error);
318
- domain = undefined;
319
253
  isSecureConnection = false;
320
254
  }
321
255
 
322
256
  const commonAttributes = {
323
257
  secure: true,
324
258
  sameSite: "None",
325
- domain: domain,
326
259
  path: "/",
327
- httpOnly: false,
328
260
  expires: new Date(0),
329
261
  };
330
262
 
@@ -339,29 +271,18 @@ const clearAuthCookies = async (res, appUrl) => {
339
271
  // Clear cookies with domain
340
272
  cookieNames.forEach((cookieName) => {
341
273
  res.clearCookie(cookieName, commonAttributes);
342
-
343
- // Also try clearing without domain for root domain
344
- if (domain === ".propro.so") {
345
- const rootAttributes = { ...commonAttributes };
346
- delete rootAttributes.domain;
347
- res.clearCookie(cookieName, rootAttributes);
348
- }
349
274
  });
350
275
 
351
276
  try {
352
- // Skip extension cookie clearing if not in extension context
277
+ // Handle extension cookies if in extension context
353
278
  const extensionClearPromises = cookieNames.map(
354
279
  (name) =>
355
280
  new Promise((resolve) => {
356
281
  chrome.cookies.remove(
357
282
  {
358
- url: `https://${
359
- domain?.startsWith(".")
360
- ? domain.slice(1)
361
- : domain || "propro.so"
362
- }`,
283
+ url: processedAppUrl,
363
284
  name,
364
- domain: domain,
285
+ secure: true,
365
286
  },
366
287
  resolve
367
288
  );
@@ -376,7 +297,6 @@ const clearAuthCookies = async (res, appUrl) => {
376
297
  }
377
298
 
378
299
  console.log("Auth cookies cleared successfully", {
379
- domain,
380
300
  cookieNames,
381
301
  sameSite: commonAttributes.sameSite,
382
302
  });