@tmlmobilidade/interfaces 20250929.1324.18 → 20251001.1515.2
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/dist/src/providers/auth/auth.js +15 -22
- package/package.json +1 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { roles, sessions, users, verificationTokens } from '../../interfaces/index.js';
|
|
3
3
|
import { sendWelcomeEmail } from '@tmlmobilidade/emails';
|
|
4
4
|
import { getAppConfig, HttpException, HttpStatus } from '@tmlmobilidade/lib';
|
|
5
|
-
import { AsyncSingletonProxy, Dates, generateRandomString, generateRandomToken } from '@tmlmobilidade/utils';
|
|
5
|
+
import { AsyncSingletonProxy, Dates, generateRandomString, generateRandomToken, mergeObjects } from '@tmlmobilidade/utils';
|
|
6
6
|
import bcrypt from 'bcryptjs';
|
|
7
7
|
/* * */
|
|
8
8
|
class AuthProvider {
|
|
@@ -29,28 +29,21 @@ class AuthProvider {
|
|
|
29
29
|
// Get the user and their roles
|
|
30
30
|
const userData = await this.getUser(sessionToken);
|
|
31
31
|
const rolesData = await roles.findMany({ _id: { $in: userData.role_ids } });
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
const allPermissions = [...rolesData.flatMap(role => role.permissions), ...userData.permissions];
|
|
33
|
+
const permissionsMap = new Map();
|
|
34
|
+
for (const permission of allPermissions) {
|
|
35
|
+
const key = `${permission.scope}:${permission.action}`;
|
|
36
|
+
if (permissionsMap.has(key)) {
|
|
37
|
+
const existingPermission = permissionsMap.get(key);
|
|
38
|
+
if (!existingPermission) {
|
|
39
|
+
throw new HttpException(HttpStatus.INTERNAL_SERVER_ERROR, 'Error getting permissions');
|
|
40
|
+
}
|
|
41
|
+
permissionsMap.set(key, mergeObjects(existingPermission, permission));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
permissionsMap.set(key, permission);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
// If no permission found, throw an error
|
|
48
|
-
if (!combinedPermissions?.length) {
|
|
49
|
-
throw new HttpException(HttpStatus.FORBIDDEN, 'User does not have permissions');
|
|
50
|
-
}
|
|
51
|
-
//
|
|
52
|
-
// Else, return the permission
|
|
53
|
-
return combinedPermissions;
|
|
46
|
+
return Array.from(permissionsMap.values());
|
|
54
47
|
}
|
|
55
48
|
/**
|
|
56
49
|
* Gets a user by their session token.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmlmobilidade/interfaces",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20251001.1515.2",
|
|
4
4
|
"author": "João de Vasconcelos & Jusi Monteiro",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"homepage": "https://github.com/tmlmobilidade/services#readme",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"bcryptjs": "3.0.2",
|
|
48
48
|
"luxon": "3.7.2",
|
|
49
49
|
"mongodb": "6.19.0",
|
|
50
|
-
"nodemailer": "7.0.6",
|
|
51
50
|
"oci-common": "2.116.2",
|
|
52
51
|
"oci-objectstorage": "2.116.2",
|
|
53
52
|
"zod": "3.25.76"
|
|
@@ -56,7 +55,6 @@
|
|
|
56
55
|
"@carrismetropolitana/eslint": "20250622.1204.50",
|
|
57
56
|
"@types/luxon": "3.7.1",
|
|
58
57
|
"@types/node": "24.3.1",
|
|
59
|
-
"@types/nodemailer": "7.0.1",
|
|
60
58
|
"resolve-tspaths": "0.8.23",
|
|
61
59
|
"rimraf": "6.0.1",
|
|
62
60
|
"typescript": "5.9.2"
|