propro-utils 1.4.82 → 1.4.84

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.82",
3
+ "version": "1.4.84",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -71,9 +71,12 @@ class AuthMiddleware {
71
71
  };
72
72
 
73
73
  handleLogin = async (req, res) => {
74
- const { email, username, password } = req.body;
74
+ const { email, name, password } = req.body;
75
75
  const { returnTokens } = req.query;
76
76
 
77
+ console.log('returnTokens:', returnTokens);
78
+ console.log('email:', email);
79
+
77
80
  try {
78
81
  const response = await this.proxyToAuthServer(
79
82
  req,
@@ -81,7 +84,7 @@ class AuthMiddleware {
81
84
  'POST',
82
85
  {
83
86
  email,
84
- username,
87
+ name,
85
88
  password,
86
89
  clientId: this.options.clientId,
87
90
  redirectUri: this.options.redirectUri,
@@ -89,6 +92,8 @@ class AuthMiddleware {
89
92
  }
90
93
  );
91
94
 
95
+ console.log('response:', JSON.stringify(response.data));
96
+
92
97
  const { account, tokens } = response.data;
93
98
  const user = await checkIfUserExists(this.userSchema, account.accountId);
94
99
 
@@ -302,10 +307,19 @@ class AuthMiddleware {
302
307
  }
303
308
  };
304
309
 
310
+ pathRequiresAccessToken = path => {
311
+ return (
312
+ !path.includes('/api/v1/auth/login') &&
313
+ !path.includes('/api/v1/auth/register')
314
+ );
315
+ };
316
+
305
317
  proxyToAuthServer = async (req, path) => {
306
- const accessToken = req.cookies['x-access-token'];
307
- if (!accessToken) {
308
- throw new Error('No access token provided');
318
+ if (this.pathRequiresAccessToken(path)) {
319
+ const accessToken = req.cookies['x-access-token'];
320
+ if (!accessToken) {
321
+ throw new Error('No access token provided');
322
+ }
309
323
  }
310
324
 
311
325
  const formattedAuthUrl = formatRedirectUrl(this.options.authUrl);