propro-utils 1.7.26 → 1.7.27

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.
@@ -70,10 +70,14 @@ const authValidation = (requiredPermissions = []) => {
70
70
 
71
71
  req.account = accountId;
72
72
 
73
- const user = await checkIfUserExists(accountId);
74
- if (!user) {
75
- return res.status(403).json({ error: 'User not found' });
73
+ let user = null;
74
+ try {
75
+ user = await checkIfUserExists(account.accountId);
76
+ if (!user) throw new Error('User not found');
77
+ } catch (error) {
78
+ return res.status(403).json({error: error?.message || 'User not found'});
76
79
  }
80
+
77
81
  req.user = user.id;
78
82
  next();
79
83
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.7.26",
3
+ "version": "1.7.27",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "private": false,
@@ -93,9 +93,14 @@ class AuthMiddleware {
93
93
  const response = await this.proxyToAuthServer(req, `/api/v1/auth/login`);
94
94
 
95
95
  const { account, tokens } = response.data;
96
- console.log('account:', account);
97
- const user = await checkIfUserExists(account.accountId);
98
- console.log('user:', user);
96
+
97
+ let user = null;
98
+ try {
99
+ user = await checkIfUserExists(account.accountId);
100
+ if (!user) throw new Error('User not found');
101
+ } catch (error) {
102
+ return res.status(403).json({error: error?.message || 'User not found'});
103
+ }
99
104
 
100
105
  if (returnTokens === 'true') {
101
106
  res.status(response.status).json({ account, user, tokens });
@@ -160,10 +165,12 @@ class AuthMiddleware {
160
165
  this.options.redirectUri
161
166
  );
162
167
 
163
- const user = await checkIfUserExists(account.accountId);
164
-
165
- if (!user) {
166
- throw new Error('User not found');
168
+ let user = null;
169
+ try {
170
+ user = await checkIfUserExists(account.accountId);
171
+ if (!user) throw new Error('User not found');
172
+ } catch (error) {
173
+ return res.status(403).json({error: error?.message || 'User not found'});
167
174
  }
168
175
 
169
176
  await setAuthCookies(res, tokens, account, user, this.options.appUrl);
@@ -120,7 +120,7 @@ const VerifyAccount = requiredPermissions => {
120
120
  req.user = userResponse.data;
121
121
  return next();
122
122
  } catch (networkError) {
123
- return res.status(500).json({ error: 'Error validating token' });
123
+ return res.status(401).json({ error: 'Error validating token' });
124
124
  }
125
125
  }
126
126
  };