propro-utils 1.7.41 → 1.7.43

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.
@@ -37,18 +37,15 @@ const ServiceManager = require('../utils/serviceManager');
37
37
  const authValidation = (requiredPermissions = []) => {
38
38
  return async (req, res, next) => {
39
39
  try {
40
- console.log("AUTH VALIDATION: 1", req.cookies);
41
40
  const accessToken =
42
41
  req.cookies?.['x-access-token'] ||
43
42
  req.headers.authorization?.split(' ')[1];
44
43
 
45
- console.log("AUTH VALIDATION: 2", accessToken);
46
44
  if (!accessToken) {
47
45
  return res.status(403).json({ error: 'Access token is required' });
48
46
  }
49
47
 
50
48
  const fetchPermission = async () => {
51
- console.log("AUTH VALIDATION: fetchPermission()");
52
49
  const response = await axios.post(
53
50
  `${process.env.AUTH_URL}/api/v1/auth/validateToken`,
54
51
  {
@@ -58,43 +55,32 @@ const authValidation = (requiredPermissions = []) => {
58
55
  );
59
56
  return response.data;
60
57
  };
61
- console.log("AUTH VALIDATION: 3");
62
58
  const redisClient = await ServiceManager.getService('RedisClient');
63
- console.log("AUTH VALIDATION: 4");
64
59
  const cacheKey = `account:permissions:${accessToken}`;
65
- console.log("AUTH VALIDATION: 5");
66
60
  const { accountId, validPermissions } = await getOrSetCache(
67
61
  redisClient,
68
62
  cacheKey,
69
63
  fetchPermission,
70
64
  1800
71
65
  );
72
- console.log("AUTH VALIDATION: 6", validPermissions);
73
66
 
74
67
  if (!validPermissions) {
75
68
  return res.status(403).json({ error: 'Invalid permissions' });
76
69
  }
77
70
 
78
- console.log("AUTH VALIDATION: 7", req.account);
79
-
80
71
  req.account = accountId;
81
72
 
82
73
  let user = null;
83
74
  try {
84
- console.log("AUTH VALIDATION: 8");
85
75
  user = await checkIfUserExists(accountId);
86
- console.log("AUTH VALIDATION: 9", user);
87
76
  if (!user) throw new Error('User not found');
88
77
  } catch (error) {
89
- console.log("AUTH VALIDATION: ERROR 1", error);
90
78
  return res.status(403).json({error: error?.message || 'User not found'});
91
79
  }
92
80
 
93
81
  req.user = user.id;
94
- console.log("AUTH VALIDATION: 10", req.user);
95
82
  next();
96
83
  } catch (error) {
97
- console.log("AUTH VALIDATION: ERROR 2", error);
98
84
  if (error.response && error.response.status) {
99
85
  next(new Error(error.response.data.message));
100
86
  }
@@ -177,18 +177,42 @@ const checkIfUserExists = async accountId => {
177
177
  console.warn("Invalid accountId provided:", accountId);
178
178
  throw new Error("Invalid accountId provided");
179
179
  }
180
+ console.log("ACCOUNT INFO: 1");
180
181
 
181
182
  try {
182
- const schemaResults = await Promise.all([
183
+ /*
184
+ const schemaResults = await Promise.all([
183
185
  ServiceManager.getService("UserSchema"),
184
186
  ServiceManager.getService("UserStyleSchema"),
185
187
  ServiceManager.getService("FolderSchema"),
186
188
  ServiceManager.getService("ThemeSchema"),
187
189
  ]);
188
190
 
191
+ console.log("ACCOUNT INFO: 2", schemaResults);
192
+
189
193
  const [userSchema, userStyleSchema, folderSchema, themeSchema] =
190
194
  schemaResults;
191
195
 
196
+ */
197
+ const userSchema = await ServiceManager.getService("UserSchema");
198
+
199
+ console.log("ACCOUNT INFO: 2", userSchema);
200
+ const userStyleSchema = await ServiceManager.getService("UserStyleSchema");
201
+
202
+ console.log("ACCOUNT INFO: 3", userStyleSchema);
203
+ const folderSchema = await ServiceManager.getService("FolderSchema");
204
+ console.log("ACCOUNT INFO: 4", folderSchema);
205
+ const themeSchema = await ServiceManager.getService("ThemeSchema");
206
+ console.log("ACCOUNT INFO: 5", themeSchema);
207
+
208
+ const schemaResults = [
209
+ userSchema,
210
+ userStyleSchema,
211
+ folderSchema,
212
+ themeSchema,
213
+ ];
214
+
215
+
192
216
  if (!userSchema) {
193
217
  throw new Error("UserSchema service not available");
194
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.7.41",
3
+ "version": "1.7.43",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "private": false,