propro-utils 1.4.43 → 1.4.45
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 +1 -1
- package/src/server/index.js +8 -11
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -56,6 +56,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
56
56
|
if (req.cookies) {
|
|
57
57
|
refreshToken = req.cookies['x-refresh-token'];
|
|
58
58
|
}
|
|
59
|
+
console.log('refreshing tokens: ', refreshToken);
|
|
59
60
|
if (!refreshToken) {
|
|
60
61
|
const redirectUrl = constructRedirectUrl(
|
|
61
62
|
clientUrl,
|
|
@@ -71,6 +72,9 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
71
72
|
const formatedAuthUrl = formatRedirectUrl(authUrl);
|
|
72
73
|
|
|
73
74
|
let response;
|
|
75
|
+
let account;
|
|
76
|
+
let access;
|
|
77
|
+
let refresh;
|
|
74
78
|
|
|
75
79
|
try {
|
|
76
80
|
response = await post(
|
|
@@ -84,12 +88,12 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
84
88
|
},
|
|
85
89
|
}
|
|
86
90
|
);
|
|
91
|
+
|
|
92
|
+
({ account, access, refresh } = response.data);
|
|
87
93
|
} catch (error) {
|
|
88
|
-
console.error('an error occur: ', error);
|
|
94
|
+
console.error('an error occur: ', error.message);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
const { account, access, refresh } = response.data;
|
|
92
|
-
|
|
93
97
|
if (!account || !access || !refresh) {
|
|
94
98
|
return res
|
|
95
99
|
.status(401)
|
|
@@ -128,6 +132,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
128
132
|
return res.redirect(urlToRedirect);
|
|
129
133
|
}
|
|
130
134
|
} catch (error) {
|
|
135
|
+
console.log('Unauthorized: ', error.message);
|
|
131
136
|
res.status(401).send('Unauthorized: Invalid or expired token');
|
|
132
137
|
}
|
|
133
138
|
};
|
|
@@ -143,14 +148,6 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
143
148
|
* @return {string} The constructed redirect URL.
|
|
144
149
|
*/
|
|
145
150
|
function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
|
|
146
|
-
console.log(
|
|
147
|
-
'constructRedirectUrl',
|
|
148
|
-
clientUrl,
|
|
149
|
-
appName,
|
|
150
|
-
clientId,
|
|
151
|
-
redirectUri
|
|
152
|
-
);
|
|
153
|
-
|
|
154
151
|
const urlToRedirect = formatRedirectUrl(clientUrl);
|
|
155
152
|
|
|
156
153
|
return `${urlToRedirect}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
|