propro-utils 1.4.19 → 1.4.20

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server/index.js +22 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.4.19",
3
+ "version": "1.4.20",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -151,16 +151,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
151
151
 
152
152
  console.log('redirectUrl', redirectUrl);
153
153
 
154
- let urlToRedirect;
155
-
156
- if (!redirectUrl.startsWith('http://') && !redirectUrl.startsWith('https://')) {
157
- if (redirectUrl.includes('localhost')) {
158
- urlToRedirect = `http://${redirectUrl}`;
159
- } else {
160
- urlToRedirect = `https://${redirectUrl}`;
161
- }
162
- }
163
-
154
+ const urlToRedirect = formatRedirectUrl(clientUrl);
164
155
 
165
156
  console.log('urlToRedirect', urlToRedirect);
166
157
 
@@ -185,15 +176,31 @@ function proproAuthMiddleware(options = {}, userSchema) {
185
176
  function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
186
177
  console.log('constructRedirectUrl', clientUrl, appName, clientId, redirectUri);
187
178
 
188
- if (!clientUrl.startsWith('http://') && !clientUrl.startsWith('https://')) {
189
- if (clientUrl.includes('localhost')) {
190
- clientUrl = `http://${clientUrl}`;
179
+ const urlToRedirect = formatRedirectUrl(clientUrl)
180
+
181
+ return `${urlToRedirect}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
182
+ }
183
+
184
+ /**
185
+ * Formats the redirect URL by adding 'http://' or 'https://' if necessary.
186
+ *
187
+ * @param {string} redirectUrl - The URL to be redirected.
188
+ * @return {string} The formatted redirect URL.
189
+ */
190
+ function formatRedirectUrl(redirectUrl) {
191
+ let urlToRedirect;
192
+
193
+ if (!redirectUrl.startsWith('http://') && !redirectUrl.startsWith('https://')) {
194
+ if (redirectUrl.includes('localhost')) {
195
+ urlToRedirect = `http://${redirectUrl}`;
191
196
  } else {
192
- clientUrl = `https://${clientUrl}`;
197
+ urlToRedirect = `https://${redirectUrl}`;
193
198
  }
199
+ } else {
200
+ urlToRedirect = redirectUrl;
194
201
  }
195
202
 
196
- return `${clientUrl}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
203
+ return urlToRedirect;
197
204
  }
198
205
 
199
206