propro-utils 1.3.41 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.3.41",
3
+ "version": "1.3.43",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ const {post} = require("axios");
8
8
  /**
9
9
  * Middleware for handling authentication and authorization.
10
10
  *
11
- * @param {object} [options={}] - The options for configuring the authentication middleware.
11
+ * @param {object} [options={}] - The options for configuring the auth entication middleware.
12
12
  * @param {string} [options.secret="RESTFULAPIs"] - The secret key used for authentication.
13
13
  * @param {string} [options.authUrl=process.env.AUTH_URL] - The authentication URL.
14
14
  * @param {string} [options.clientId=process.env.CLIENT_ID] - The client ID.
@@ -41,27 +41,41 @@ function proproAuthMiddleware(options = {}, userSchema) {
41
41
  const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
42
42
  redirectUri
43
43
  )}`;
44
- res.status(200).json({redirectUrl});
44
+ return res.status(200).json({redirectUrl});
45
45
  }
46
46
 
47
47
  if (req.path === "/api/refreshToken") {
48
+ console.log("refresh token");
48
49
  const refreshToken = req.cookies["x-refresh-token"];
50
+ console.log("refreshToken", refreshToken);
49
51
  if (!refreshToken) {
50
52
  const authClientUrl = `${clientUrl}/signin`;
51
53
  const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
52
54
  redirectUri
53
55
  )}`;
54
- res.status(401).json({redirectUrl, error: "No refresh token provided"});
56
+ return res.status(401).json({redirectUrl, error: "No refresh token provided"});
55
57
  }
56
58
 
57
- const {accountData, access, refresh} = await post(`${authUrl}/api/v1/auth/refreshTokens`, {
59
+ const response = await post(`${authUrl}/api/v1/auth/refreshTokens`, {
58
60
  refreshToken
59
61
  }, {
60
62
  params: {
61
63
  actionType: "refresh",
62
64
  }
63
65
  });
66
+
67
+ console.log("response", response.data);
68
+ console.log("response.data.tokens", response.data.tokens);
64
69
 
70
+ const {account, access, refresh} = response.data;
71
+
72
+ console.log("accountData", account);
73
+ console.log("access", access);
74
+ console.log("refresh", refresh);
75
+
76
+ if (!account || !access || !refresh) {
77
+ return res.status(401).json({error: "Invalid or expired refresh token"});
78
+ }
65
79
 
66
80
  const currentDateTime = new Date();
67
81