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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.83",
3
+ "version": "1.4.85",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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
- const accessToken = req.cookies['x-access-token'];
312
- if (!accessToken) {
313
- throw new Error('No access token provided');
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