propro-utils 1.6.8 → 1.7.0

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.6.8",
3
+ "version": "1.7.0",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -124,12 +124,8 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
124
124
  isSecureConnection = false;
125
125
  }
126
126
  if (domain?.includes("propro.so")) {
127
- // Handle both main domain and subdomains of propro.so
128
- if (domain.startsWith("short.")) {
129
- domain = ".short.propro.so";
130
- } else {
131
- domain = ".propro.so";
132
- }
127
+ // Set root domain for all propro.so subdomains
128
+ domain = ".propro.so";
133
129
  }
134
130
 
135
131
  console.log("Cookie configuration:", {
@@ -138,6 +134,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
138
134
  protocol: urlObj.protocol,
139
135
  originalUrl: appUrl,
140
136
  processedUrl: processedAppUrl,
137
+ hostname: urlObj.hostname,
141
138
  });
142
139
  } catch (error) {
143
140
  console.error("Invalid appUrl:", { error, appUrl });
@@ -149,29 +146,32 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
149
146
  const isLocalhost =
150
147
  !domain || domain === "localhost" || domain.includes("localhost");
151
148
 
149
+ // Base attributes that work across domains
152
150
  const commonAttributes = {
153
- secure: isSecureConnection,
154
- sameSite: isSecureConnection ? "None" : "Lax",
155
- domain,
151
+ secure: true, // Always use secure in production
152
+ sameSite: "None", // Required for cross-domain
153
+ domain: domain,
156
154
  path: "/",
157
155
  httpOnly: false,
158
156
  expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
159
157
  };
160
158
 
161
- console.log("Cookie attributes:", commonAttributes);
162
-
163
159
  const httpOnlyCookies = {
164
160
  "x-refresh-token": {
165
161
  value: tokens.refresh.token,
166
162
  maxAge: refreshMaxAge,
167
163
  httpOnly: true,
168
- secure: isSecureConnection,
164
+ secure: true,
165
+ sameSite: "None",
166
+ domain: domain,
169
167
  },
170
168
  "x-access-token": {
171
169
  value: tokens.access.token,
172
170
  maxAge: accessMaxAge,
173
171
  httpOnly: true,
174
- secure: isSecureConnection,
172
+ secure: true,
173
+ sameSite: "None",
174
+ domain: domain,
175
175
  },
176
176
  };
177
177
 
@@ -184,50 +184,77 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
184
184
  value: safeStringify(sanitizedUser),
185
185
  maxAge: refreshMaxAge,
186
186
  httpOnly: false,
187
- secure: isSecureConnection,
187
+ secure: true,
188
+ sameSite: "None",
189
+ domain: domain,
188
190
  },
189
191
  account: {
190
192
  value: safeStringify(sanitizedAccount),
191
193
  maxAge: refreshMaxAge,
192
194
  httpOnly: false,
193
- secure: isSecureConnection,
195
+ secure: true,
196
+ sameSite: "None",
197
+ domain: domain,
194
198
  },
195
199
  has_account_token: {
196
200
  value: JSON.stringify({ value: "true", expires: accessMaxAge }),
197
201
  maxAge: accessMaxAge,
198
202
  httpOnly: false,
199
- secure: isSecureConnection,
203
+ secure: true,
204
+ sameSite: "None",
205
+ domain: domain,
200
206
  },
201
207
  };
202
208
 
203
209
  try {
210
+ // Set each cookie individually with full attributes
204
211
  Object.entries({ ...httpOnlyCookies, ...regularCookies }).forEach(
205
212
  ([name, config]) => {
206
- res.cookie(name, config.value, {
213
+ // Ensure all required attributes are explicitly set
214
+ const cookieConfig = {
207
215
  ...commonAttributes,
208
216
  ...config,
209
- });
217
+ domain: domain, // Explicitly set domain for each cookie
218
+ };
219
+
220
+ 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
+ }
210
228
  }
211
229
  );
212
230
 
213
- const extensionCookiePromises = Object.entries({
214
- ...httpOnlyCookies,
215
- ...regularCookies,
216
- }).map(([name, config]) => {
217
- return setChromeExtensionCookie({
218
- url: `https://${domain || "propro.so"}`,
219
- name,
220
- value: config.value,
221
- secure: true,
222
- httpOnly: !!config.httpOnly,
223
- sameSite: "no_restriction",
224
- path: "/",
225
- expirationDate: Math.floor((Date.now() + config.maxAge) / 1000),
226
- domain: domain?.startsWith(".") ? domain : `.${domain || "propro.so"}`,
231
+ // Skip extension cookie setting if not in extension context
232
+ try {
233
+ const extensionCookiePromises = Object.entries({
234
+ ...httpOnlyCookies,
235
+ ...regularCookies,
236
+ }).map(([name, config]) => {
237
+ return setChromeExtensionCookie({
238
+ url: `https://${
239
+ domain?.startsWith(".") ? domain.slice(1) : domain || "propro.so"
240
+ }`,
241
+ name,
242
+ value: config.value,
243
+ secure: true,
244
+ httpOnly: !!config.httpOnly,
245
+ sameSite: "no_restriction",
246
+ path: "/",
247
+ expirationDate: Math.floor((Date.now() + config.maxAge) / 1000),
248
+ domain: domain,
249
+ });
227
250
  });
228
- });
229
251
 
230
- await Promise.allSettled(extensionCookiePromises);
252
+ Promise.allSettled(extensionCookiePromises).catch(() => {
253
+ // Ignore extension errors
254
+ });
255
+ } catch (error) {
256
+ // Ignore extension errors
257
+ }
231
258
 
232
259
  console.log("Auth cookies set successfully", {
233
260
  domain,
@@ -275,12 +302,7 @@ const clearAuthCookies = async (res, appUrl) => {
275
302
  isSecureConnection = false;
276
303
  }
277
304
  if (domain?.includes("propro.so")) {
278
- // Handle both main domain and subdomains of propro.so
279
- if (domain.startsWith("short.")) {
280
- domain = "short.propro.so";
281
- } else {
282
- domain = "propro.so";
283
- }
305
+ domain = ".propro.so";
284
306
  }
285
307
 
286
308
  console.log("Clear cookies configuration:", {
@@ -289,6 +311,7 @@ const clearAuthCookies = async (res, appUrl) => {
289
311
  protocol: urlObj.protocol,
290
312
  originalUrl: appUrl,
291
313
  processedUrl: processedAppUrl,
314
+ hostname: urlObj.hostname,
292
315
  });
293
316
  } catch (error) {
294
317
  console.error("Invalid appUrl:", error);
@@ -297,16 +320,14 @@ const clearAuthCookies = async (res, appUrl) => {
297
320
  }
298
321
 
299
322
  const commonAttributes = {
300
- secure: isSecureConnection,
301
- sameSite: isSecureConnection ? "None" : "Lax",
302
- domain,
323
+ secure: true,
324
+ sameSite: "None",
325
+ domain: domain,
303
326
  path: "/",
304
327
  httpOnly: false,
305
328
  expires: new Date(0),
306
329
  };
307
330
 
308
- console.log("Clear cookie attributes:", commonAttributes);
309
-
310
331
  const cookieNames = [
311
332
  "x-refresh-token",
312
333
  "x-access-token",
@@ -315,26 +336,41 @@ const clearAuthCookies = async (res, appUrl) => {
315
336
  "has_account_token",
316
337
  ];
317
338
 
318
- // Clear web cookies
339
+ // Clear cookies with domain
319
340
  cookieNames.forEach((cookieName) => {
320
341
  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
+ }
321
349
  });
322
350
 
323
351
  try {
352
+ // Skip extension cookie clearing if not in extension context
324
353
  const extensionClearPromises = cookieNames.map(
325
354
  (name) =>
326
355
  new Promise((resolve) => {
327
356
  chrome.cookies.remove(
328
357
  {
329
- url: `https://${domain || "mapmap.app"}`,
358
+ url: `https://${
359
+ domain?.startsWith(".")
360
+ ? domain.slice(1)
361
+ : domain || "propro.so"
362
+ }`,
330
363
  name,
364
+ domain: domain,
331
365
  },
332
366
  resolve
333
367
  );
334
368
  })
335
369
  );
336
370
 
337
- await Promise.allSettled(extensionClearPromises);
371
+ Promise.allSettled(extensionClearPromises).catch(() => {
372
+ // Ignore extension errors
373
+ });
338
374
  } catch (error) {
339
375
  // Not in extension context, ignore
340
376
  }