propro-utils 1.6.6 → 1.6.8
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
|
@@ -100,6 +100,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
100
100
|
|
|
101
101
|
// Domain configuration
|
|
102
102
|
let domain;
|
|
103
|
+
let isSecureConnection = false;
|
|
103
104
|
try {
|
|
104
105
|
// Handle URLs that don't include the protocol
|
|
105
106
|
let processedAppUrl = appUrl;
|
|
@@ -111,24 +112,37 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
111
112
|
processedAppUrl = `https://${appUrl}`;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
const urlObj = new URL(processedAppUrl);
|
|
116
|
+
domain = urlObj.hostname;
|
|
117
|
+
isSecureConnection = urlObj.protocol === "https:";
|
|
118
|
+
|
|
115
119
|
if (domain?.includes("mapmap.app")) {
|
|
116
120
|
domain = ".mapmap.app";
|
|
117
121
|
}
|
|
118
122
|
if (domain?.includes("localhost")) {
|
|
119
123
|
domain = undefined;
|
|
124
|
+
isSecureConnection = false;
|
|
120
125
|
}
|
|
121
126
|
if (domain?.includes("propro.so")) {
|
|
122
127
|
// Handle both main domain and subdomains of propro.so
|
|
123
128
|
if (domain.startsWith("short.")) {
|
|
124
|
-
domain = "short.propro.so";
|
|
129
|
+
domain = ".short.propro.so";
|
|
125
130
|
} else {
|
|
126
|
-
domain = "propro.so";
|
|
131
|
+
domain = ".propro.so";
|
|
127
132
|
}
|
|
128
133
|
}
|
|
134
|
+
|
|
135
|
+
console.log("Cookie configuration:", {
|
|
136
|
+
domain,
|
|
137
|
+
isSecure: isSecureConnection,
|
|
138
|
+
protocol: urlObj.protocol,
|
|
139
|
+
originalUrl: appUrl,
|
|
140
|
+
processedUrl: processedAppUrl,
|
|
141
|
+
});
|
|
129
142
|
} catch (error) {
|
|
130
143
|
console.error("Invalid appUrl:", { error, appUrl });
|
|
131
144
|
domain = undefined;
|
|
145
|
+
isSecureConnection = false;
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
// Determine if we're in a local development environment
|
|
@@ -136,22 +150,28 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
136
150
|
!domain || domain === "localhost" || domain.includes("localhost");
|
|
137
151
|
|
|
138
152
|
const commonAttributes = {
|
|
139
|
-
secure:
|
|
140
|
-
sameSite:
|
|
153
|
+
secure: isSecureConnection,
|
|
154
|
+
sameSite: isSecureConnection ? "None" : "Lax",
|
|
141
155
|
domain,
|
|
142
156
|
path: "/",
|
|
157
|
+
httpOnly: false,
|
|
158
|
+
expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
|
|
143
159
|
};
|
|
144
160
|
|
|
161
|
+
console.log("Cookie attributes:", commonAttributes);
|
|
162
|
+
|
|
145
163
|
const httpOnlyCookies = {
|
|
146
164
|
"x-refresh-token": {
|
|
147
165
|
value: tokens.refresh.token,
|
|
148
166
|
maxAge: refreshMaxAge,
|
|
149
167
|
httpOnly: true,
|
|
168
|
+
secure: isSecureConnection,
|
|
150
169
|
},
|
|
151
170
|
"x-access-token": {
|
|
152
171
|
value: tokens.access.token,
|
|
153
172
|
maxAge: accessMaxAge,
|
|
154
173
|
httpOnly: true,
|
|
174
|
+
secure: isSecureConnection,
|
|
155
175
|
},
|
|
156
176
|
};
|
|
157
177
|
|
|
@@ -163,14 +183,20 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
163
183
|
user: {
|
|
164
184
|
value: safeStringify(sanitizedUser),
|
|
165
185
|
maxAge: refreshMaxAge,
|
|
186
|
+
httpOnly: false,
|
|
187
|
+
secure: isSecureConnection,
|
|
166
188
|
},
|
|
167
189
|
account: {
|
|
168
190
|
value: safeStringify(sanitizedAccount),
|
|
169
191
|
maxAge: refreshMaxAge,
|
|
192
|
+
httpOnly: false,
|
|
193
|
+
secure: isSecureConnection,
|
|
170
194
|
},
|
|
171
195
|
has_account_token: {
|
|
172
196
|
value: JSON.stringify({ value: "true", expires: accessMaxAge }),
|
|
173
197
|
maxAge: accessMaxAge,
|
|
198
|
+
httpOnly: false,
|
|
199
|
+
secure: isSecureConnection,
|
|
174
200
|
},
|
|
175
201
|
};
|
|
176
202
|
|
|
@@ -225,6 +251,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
225
251
|
*/
|
|
226
252
|
const clearAuthCookies = async (res, appUrl) => {
|
|
227
253
|
let domain;
|
|
254
|
+
let isSecureConnection = false;
|
|
228
255
|
try {
|
|
229
256
|
// Handle URLs that don't include the protocol
|
|
230
257
|
let processedAppUrl = appUrl;
|
|
@@ -236,12 +263,16 @@ const clearAuthCookies = async (res, appUrl) => {
|
|
|
236
263
|
processedAppUrl = `https://${appUrl}`;
|
|
237
264
|
}
|
|
238
265
|
|
|
239
|
-
|
|
266
|
+
const urlObj = new URL(processedAppUrl);
|
|
267
|
+
domain = urlObj.hostname;
|
|
268
|
+
isSecureConnection = urlObj.protocol === "https:";
|
|
269
|
+
|
|
240
270
|
if (domain?.includes("mapmap.app")) {
|
|
241
271
|
domain = ".mapmap.app";
|
|
242
272
|
}
|
|
243
273
|
if (domain?.includes("localhost")) {
|
|
244
274
|
domain = undefined;
|
|
275
|
+
isSecureConnection = false;
|
|
245
276
|
}
|
|
246
277
|
if (domain?.includes("propro.so")) {
|
|
247
278
|
// Handle both main domain and subdomains of propro.so
|
|
@@ -251,22 +282,31 @@ const clearAuthCookies = async (res, appUrl) => {
|
|
|
251
282
|
domain = "propro.so";
|
|
252
283
|
}
|
|
253
284
|
}
|
|
285
|
+
|
|
286
|
+
console.log("Clear cookies configuration:", {
|
|
287
|
+
domain,
|
|
288
|
+
isSecure: isSecureConnection,
|
|
289
|
+
protocol: urlObj.protocol,
|
|
290
|
+
originalUrl: appUrl,
|
|
291
|
+
processedUrl: processedAppUrl,
|
|
292
|
+
});
|
|
254
293
|
} catch (error) {
|
|
255
294
|
console.error("Invalid appUrl:", error);
|
|
256
295
|
domain = undefined;
|
|
296
|
+
isSecureConnection = false;
|
|
257
297
|
}
|
|
258
298
|
|
|
259
|
-
// Determine if we're in a local development environment
|
|
260
|
-
const isLocalhost =
|
|
261
|
-
!domain || domain === "localhost" || domain.includes("localhost");
|
|
262
|
-
|
|
263
299
|
const commonAttributes = {
|
|
264
|
-
secure:
|
|
265
|
-
sameSite:
|
|
300
|
+
secure: isSecureConnection,
|
|
301
|
+
sameSite: isSecureConnection ? "None" : "Lax",
|
|
266
302
|
domain,
|
|
267
303
|
path: "/",
|
|
304
|
+
httpOnly: false,
|
|
305
|
+
expires: new Date(0),
|
|
268
306
|
};
|
|
269
307
|
|
|
308
|
+
console.log("Clear cookie attributes:", commonAttributes);
|
|
309
|
+
|
|
270
310
|
const cookieNames = [
|
|
271
311
|
"x-refresh-token",
|
|
272
312
|
"x-access-token",
|