@loomcore/api 0.1.36 → 0.1.37
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/services/auth.service.js +5 -2
- package/dist/services/user.service.d.ts +0 -1
- package/dist/services/user.service.js +0 -9
- package/dist/services/utils/getUserContextAuthorizations.util.d.ts +3 -0
- package/dist/services/utils/getUserContextAuthorizations.util.js +9 -0
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ import { OrganizationService } from './organization.service.js';
|
|
|
11
11
|
import { passwordUtils } from '../utils/index.js';
|
|
12
12
|
import { config } from '../config/index.js';
|
|
13
13
|
import { refreshTokenModelSpec } from '../models/refresh-token.model.js';
|
|
14
|
+
import { getUserContextAuthorizations } from './utils/getUserContextAuthorizations.util.js';
|
|
14
15
|
export class AuthService extends MultiTenantApiService {
|
|
15
16
|
refreshTokenService;
|
|
16
17
|
passwordResetTokenService;
|
|
@@ -34,10 +35,11 @@ export class AuthService extends MultiTenantApiService {
|
|
|
34
35
|
if (!passwordsMatch) {
|
|
35
36
|
throw new BadRequestError('Invalid Credentials');
|
|
36
37
|
}
|
|
38
|
+
const authorizations = await getUserContextAuthorizations(this.database, user);
|
|
37
39
|
const userContext = {
|
|
38
40
|
user: user,
|
|
39
41
|
organization: organization ?? undefined,
|
|
40
|
-
authorizations:
|
|
42
|
+
authorizations: authorizations
|
|
41
43
|
};
|
|
42
44
|
const deviceId = this.getAndSetDeviceIdCookie(req, res);
|
|
43
45
|
const loginResponse = await this.logUserIn(userContext, deviceId);
|
|
@@ -98,10 +100,11 @@ export class AuthService extends MultiTenantApiService {
|
|
|
98
100
|
const systemUserContext = getSystemUserContext();
|
|
99
101
|
const user = await this.getById(systemUserContext, activeRefreshToken.userId);
|
|
100
102
|
const organization = await this.organizationService.findOne(EmptyUserContext, { filters: { _id: { eq: user?._orgId } } });
|
|
103
|
+
const authorizations = await getUserContextAuthorizations(this.database, user);
|
|
101
104
|
const userContext = {
|
|
102
105
|
user: user,
|
|
103
106
|
organization: organization ?? undefined,
|
|
104
|
-
authorizations:
|
|
107
|
+
authorizations: authorizations
|
|
105
108
|
};
|
|
106
109
|
tokens = await this.createNewTokens(userContext, activeRefreshToken);
|
|
107
110
|
}
|
|
@@ -8,5 +8,4 @@ export declare class UserService extends MultiTenantApiService<IUser> {
|
|
|
8
8
|
get(userContext: IUserContext, queryOptions: IQueryOptions): Promise<IPagedResult<IUser>>;
|
|
9
9
|
getAll(userContext: IUserContext): Promise<IUser[]>;
|
|
10
10
|
preprocessEntity(userContext: IUserContext, entity: Partial<IUser>, isCreate: boolean, allowId?: boolean): Promise<Partial<IUser>>;
|
|
11
|
-
private getUserContextAuthorizations;
|
|
12
11
|
}
|
|
@@ -2,7 +2,6 @@ import { Value } from '@sinclair/typebox/value';
|
|
|
2
2
|
import { UserSpec, PublicUserSchema } from '@loomcore/common/models';
|
|
3
3
|
import { MultiTenantApiService } from './index.js';
|
|
4
4
|
import { IdNotFoundError, ServerError } from '../errors/index.js';
|
|
5
|
-
import { PostgresDatabase } from '../databases/postgres/postgres.database.js';
|
|
6
5
|
export class UserService extends MultiTenantApiService {
|
|
7
6
|
constructor(database) {
|
|
8
7
|
super(database, 'users', 'user', UserSpec);
|
|
@@ -42,12 +41,4 @@ export class UserService extends MultiTenantApiService {
|
|
|
42
41
|
}
|
|
43
42
|
return preparedEntity;
|
|
44
43
|
}
|
|
45
|
-
async getUserContextAuthorizations(user) {
|
|
46
|
-
if (!(this.database instanceof PostgresDatabase)) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
const orgId = user._orgId;
|
|
50
|
-
const authorizations = await this.database.getUserAuthorizations(user._id, orgId);
|
|
51
|
-
return authorizations;
|
|
52
|
-
}
|
|
53
44
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PostgresDatabase } from "../../databases/postgres/postgres.database.js";
|
|
2
|
+
export async function getUserContextAuthorizations(database, user) {
|
|
3
|
+
if (!(database instanceof PostgresDatabase)) {
|
|
4
|
+
return [];
|
|
5
|
+
}
|
|
6
|
+
const orgId = user._orgId;
|
|
7
|
+
const authorizations = await database.getUserAuthorizations(user._id, orgId);
|
|
8
|
+
return authorizations;
|
|
9
|
+
}
|