propro-utils 1.3.29 → 1.3.30

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.
@@ -40,14 +40,6 @@ const getAccountProfile = async (redisClient, userSchema, accountId) => {
40
40
  throw new Error("Invalid permissions");
41
41
  }
42
42
 
43
- // check if the user account is already in the database of the application that is using this middleware, if not, add it
44
- const user = await userSchema.findOne({ id: profileData.id });
45
- if (!user) {
46
- await userSchema.create({
47
- accountId: accountId
48
- });
49
- }
50
-
51
43
  return profileData;
52
44
 
53
45
  } catch (error) {
@@ -58,4 +50,26 @@ const getAccountProfile = async (redisClient, userSchema, accountId) => {
58
50
  }
59
51
  };
60
52
 
61
- module.exports = getAccountProfile;
53
+
54
+ /**
55
+ * Checks if a user exists based on the given account ID.
56
+ * If the user does not exist, creates a new user with the given account ID.
57
+ *
58
+ * @param {Schema} userSchema - The user schema to perform the operations on.
59
+ * @param {string} accountId - The account ID of the user to check/create.
60
+ * @returns {Promise<void>} - A promise that resolves once the check/create operation is done.
61
+ */
62
+ const checkIfUserExists = async (userSchema, accountId) => {
63
+ const user = await userSchema.findOne({ accountId
64
+ });
65
+ if (!user) {
66
+ await userSchema.create({
67
+ accountId: accountId
68
+ });
69
+ }
70
+ };
71
+
72
+ module.exports = {
73
+ getAccountProfile,
74
+ checkIfUserExists
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.3.29",
3
+ "version": "1.3.30",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -49,7 +49,7 @@ function proproAuthMiddleware(options = {}) {
49
49
 
50
50
  console.log("code", code);
51
51
 
52
- const {tokens, redirectUrl} = await exchangeToken(
52
+ const {tokens, account, redirectUrl} = await exchangeToken(
53
53
  authUrl,
54
54
  code,
55
55
  clientId,