propro-utils 1.7.25 → 1.7.27
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.
|
@@ -70,10 +70,14 @@ const authValidation = (requiredPermissions = []) => {
|
|
|
70
70
|
|
|
71
71
|
req.account = accountId;
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
let user = null;
|
|
74
|
+
try {
|
|
75
|
+
user = await checkIfUserExists(account.accountId);
|
|
76
|
+
if (!user) throw new Error('User not found');
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return res.status(403).json({error: error?.message || 'User not found'});
|
|
76
79
|
}
|
|
80
|
+
|
|
77
81
|
req.user = user.id;
|
|
78
82
|
next();
|
|
79
83
|
} catch (error) {
|
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -93,9 +93,14 @@ class AuthMiddleware {
|
|
|
93
93
|
const response = await this.proxyToAuthServer(req, `/api/v1/auth/login`);
|
|
94
94
|
|
|
95
95
|
const { account, tokens } = response.data;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
|
|
97
|
+
let user = null;
|
|
98
|
+
try {
|
|
99
|
+
user = await checkIfUserExists(account.accountId);
|
|
100
|
+
if (!user) throw new Error('User not found');
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return res.status(403).json({error: error?.message || 'User not found'});
|
|
103
|
+
}
|
|
99
104
|
|
|
100
105
|
if (returnTokens === 'true') {
|
|
101
106
|
res.status(response.status).json({ account, user, tokens });
|
|
@@ -160,10 +165,12 @@ class AuthMiddleware {
|
|
|
160
165
|
this.options.redirectUri
|
|
161
166
|
);
|
|
162
167
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
throw new Error('User not found');
|
|
168
|
+
let user = null;
|
|
169
|
+
try {
|
|
170
|
+
user = await checkIfUserExists(account.accountId);
|
|
171
|
+
if (!user) throw new Error('User not found');
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return res.status(403).json({error: error?.message || 'User not found'});
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
await setAuthCookies(res, tokens, account, user, this.options.appUrl);
|
|
@@ -101,9 +101,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
101
101
|
// Domain configuration
|
|
102
102
|
let domain;
|
|
103
103
|
try {
|
|
104
|
-
console.log('** APP URL', appUrl)
|
|
105
104
|
domain = appUrl ? new URL(appUrl).hostname : undefined;
|
|
106
|
-
console.log('** DOMAIN', domain)
|
|
107
105
|
if (domain?.includes('mapmap.app')) {
|
|
108
106
|
domain = '.mapmap.app';
|
|
109
107
|
}
|
|
@@ -114,7 +112,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
114
112
|
domain = 'propro.so';
|
|
115
113
|
}
|
|
116
114
|
} catch (error) {
|
|
117
|
-
console.log('** ERROR', error)
|
|
118
115
|
console.error('Invalid appUrl:', { error, appUrl });
|
|
119
116
|
domain = undefined;
|
|
120
117
|
}
|
|
@@ -126,10 +123,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
126
123
|
path: '/',
|
|
127
124
|
};
|
|
128
125
|
|
|
129
|
-
console.log('** MAX AGES', {
|
|
130
|
-
refreshMaxAge,
|
|
131
|
-
accessMaxAge
|
|
132
|
-
})
|
|
133
126
|
const httpOnlyCookies = {
|
|
134
127
|
'x-refresh-token': {
|
|
135
128
|
value: tokens.refresh.token,
|
|
@@ -145,7 +138,7 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
145
138
|
|
|
146
139
|
const sanitizedUser = sanitizeUser(user);
|
|
147
140
|
const sanitizedAccount = { ...account };
|
|
148
|
-
delete sanitizedAccount
|
|
141
|
+
delete sanitizedAccount.passwordHistory;
|
|
149
142
|
|
|
150
143
|
const regularCookies = {
|
|
151
144
|
user: {
|
|
@@ -162,11 +155,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
162
155
|
},
|
|
163
156
|
};
|
|
164
157
|
|
|
165
|
-
console.log('** SURVIVED OBJECTIFYING COOKIES', {
|
|
166
|
-
httpOnlyCookies,
|
|
167
|
-
regularCookies,
|
|
168
|
-
})
|
|
169
|
-
|
|
170
158
|
try {
|
|
171
159
|
Object.entries({ ...httpOnlyCookies, ...regularCookies }).forEach(
|
|
172
160
|
([name, config]) => {
|
|
@@ -177,7 +165,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
177
165
|
}
|
|
178
166
|
);
|
|
179
167
|
|
|
180
|
-
/*
|
|
181
168
|
const extensionCookiePromises = Object.entries({
|
|
182
169
|
...httpOnlyCookies,
|
|
183
170
|
...regularCookies,
|
|
@@ -196,7 +183,6 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
196
183
|
});
|
|
197
184
|
|
|
198
185
|
await Promise.allSettled(extensionCookiePromises);
|
|
199
|
-
*/
|
|
200
186
|
|
|
201
187
|
console.log('Auth cookies set successfully', {
|
|
202
188
|
domain,
|
|
@@ -120,7 +120,7 @@ const VerifyAccount = requiredPermissions => {
|
|
|
120
120
|
req.user = userResponse.data;
|
|
121
121
|
return next();
|
|
122
122
|
} catch (networkError) {
|
|
123
|
-
return res.status(
|
|
123
|
+
return res.status(401).json({ error: 'Error validating token' });
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
};
|