propro-utils 1.4.83 → 1.4.85
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 +1 -1
- package/src/server/index.js +23 -7
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -307,10 +307,29 @@ class AuthMiddleware {
|
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
|
|
310
|
+
pathRequiresAccessToken = path => {
|
|
311
|
+
return (
|
|
312
|
+
!path.includes('/api/v1/auth/login') &&
|
|
313
|
+
!path.includes('/api/v1/auth/register')
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
|
|
310
317
|
proxyToAuthServer = async (req, path) => {
|
|
311
|
-
|
|
312
|
-
if (
|
|
313
|
-
|
|
318
|
+
let accessToken = null;
|
|
319
|
+
if (this.pathRequiresAccessToken(path)) {
|
|
320
|
+
console.log('path requires access token');
|
|
321
|
+
accessToken = req.cookies['x-access-token'];
|
|
322
|
+
if (!accessToken) {
|
|
323
|
+
throw new Error('No access token provided');
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
let headers = {
|
|
328
|
+
'Content-Type': 'application/json',
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
if (accessToken) {
|
|
332
|
+
headers.Authorization = `Bearer ${accessToken}`;
|
|
314
333
|
}
|
|
315
334
|
|
|
316
335
|
const formattedAuthUrl = formatRedirectUrl(this.options.authUrl);
|
|
@@ -318,10 +337,7 @@ class AuthMiddleware {
|
|
|
318
337
|
method: req.method,
|
|
319
338
|
url: `${formattedAuthUrl}${path}`,
|
|
320
339
|
data: req.body,
|
|
321
|
-
headers:
|
|
322
|
-
Authorization: `Bearer ${accessToken}`,
|
|
323
|
-
'Content-Type': 'application/json',
|
|
324
|
-
},
|
|
340
|
+
headers: headers,
|
|
325
341
|
});
|
|
326
342
|
};
|
|
327
343
|
|