propro-utils 1.3.30 → 1.3.31

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.
@@ -60,12 +60,9 @@ const getAccountProfile = async (redisClient, userSchema, accountId) => {
60
60
  * @returns {Promise<void>} - A promise that resolves once the check/create operation is done.
61
61
  */
62
62
  const checkIfUserExists = async (userSchema, accountId) => {
63
- const user = await userSchema.findOne({ accountId
64
- });
63
+ const user = await userSchema.findOne({ accountId });
65
64
  if (!user) {
66
- await userSchema.create({
67
- accountId: accountId
68
- });
65
+ await userSchema.create({accountId});
69
66
  }
70
67
  };
71
68
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.3.30",
3
+ "version": "1.3.31",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ require("dotenv").config();
2
2
  const {
3
3
  exchangeToken,
4
4
  } = require("./middleware/verifyToken");
5
+ const {checkIfUserExists} = require("../../middlewares/account_info");
5
6
 
6
7
  /**
7
8
  * Middleware for handling authentication and authorization.
@@ -14,9 +15,10 @@ const {
14
15
  * @param {string} [options.clientUrl=process.env.CLIENT_URL] - The client URL.
15
16
  * @param {string} [options.redirectUri=process.env.REDIRECT_URI] - The redirect URI.
16
17
  * @param {string} [options.appName=process.env.APP_NAME] - The application name.
18
+ * @param {Schema} [userSchema] - The user schema to perform the operations on.
17
19
  * @returns {Function} - Express middleware function.
18
20
  */
19
- function proproAuthMiddleware(options = {}) {
21
+ function proproAuthMiddleware(options = {}, userSchema) {
20
22
  const {
21
23
  secret = "RESTFULAPIs",
22
24
  authUrl = process.env.AUTH_URL,
@@ -47,8 +49,6 @@ function proproAuthMiddleware(options = {}) {
47
49
  return res.status(400).send("No code received");
48
50
  }
49
51
 
50
- console.log("code", code);
51
-
52
52
  const {tokens, account, redirectUrl} = await exchangeToken(
53
53
  authUrl,
54
54
  code,
@@ -57,6 +57,8 @@ function proproAuthMiddleware(options = {}) {
57
57
  redirectUri
58
58
  );
59
59
 
60
+ await checkIfUserExists(userSchema, account.accountId);
61
+
60
62
  const currentDateTime = new Date();
61
63
 
62
64
  const refreshMaxAge = new Date(tokens.refresh.expires).getTime() - currentDateTime.getTime();