propro-utils 1.4.2 → 1.4.3

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.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -39,10 +39,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
39
39
 
40
40
  console.log('req.path', req.path);
41
41
  if (req.path === '/api/auth') {
42
- const authClientUrl = `${clientUrl}/signin`;
43
- const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
44
- redirectUri
45
- )}`;
42
+ const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
46
43
  return res.status(200).json({redirectUrl});
47
44
  }
48
45
 
@@ -52,10 +49,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
52
49
  console.log('refreshToken', refreshToken);
53
50
  if (!refreshToken) {
54
51
  console.log('No refresh token provided');
55
- const authClientUrl = `${clientUrl}/signin`;
56
- const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
57
- redirectUri
58
- )}`;
52
+ const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
59
53
  console.log('redirectUrl', redirectUrl);
60
54
  res
61
55
  .status(401)
@@ -159,4 +153,17 @@ function proproAuthMiddleware(options = {}, userSchema) {
159
153
  };
160
154
  }
161
155
 
156
+ /**
157
+ * Constructs the redirect URL for a client application.
158
+ *
159
+ * @param {string} clientUrl - The URL of the client application.
160
+ * @param {string} appName - The name of the application.
161
+ * @param {string} clientId - The client ID.
162
+ * @param {string} redirectUri - The redirect URI.
163
+ * @return {string} The constructed redirect URL.
164
+ */
165
+ function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
166
+ return `${clientUrl}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
167
+ }
168
+
162
169
  module.exports = proproAuthMiddleware;