propro-utils 1.4.1 → 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.1",
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
 
@@ -51,11 +48,10 @@ function proproAuthMiddleware(options = {}, userSchema) {
51
48
  const refreshToken = req.cookies['x-refresh-token'];
52
49
  console.log('refreshToken', refreshToken);
53
50
  if (!refreshToken) {
54
- const authClientUrl = `${clientUrl}/signin`;
55
- const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
56
- redirectUri
57
- )}`;
58
- return res
51
+ console.log('No refresh token provided');
52
+ const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
53
+ console.log('redirectUrl', redirectUrl);
54
+ res
59
55
  .status(401)
60
56
  .json({redirectUrl, error: 'No refresh token provided'});
61
57
  }
@@ -157,4 +153,17 @@ function proproAuthMiddleware(options = {}, userSchema) {
157
153
  };
158
154
  }
159
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
+
160
169
  module.exports = proproAuthMiddleware;