Skip to content

Commit 6bf493f

Browse files
authored
Merge pull request #1115 from joshunrau/dev
fix: remove password from user schema
2 parents 7a24f5d + b528bcc commit 6bf493f

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

apps/api/src/users/users.service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ export class UsersService {
5858
lastName,
5959
sex,
6060
username: username
61+
},
62+
omit: {
63+
hashedPassword: true
6164
}
6265
});
6366
}
6467

6568
async deleteById(id: string, { ability }: EntityOperationOptions = {}) {
6669
return this.userModel.delete({
70+
omit: {
71+
hashedPassword: true
72+
},
6773
where: { AND: [accessibleQuery(ability, 'delete', 'User')], id }
6874
});
6975
}
@@ -72,12 +78,18 @@ export class UsersService {
7278
async deleteByUsername(username: string, { ability }: EntityOperationOptions = {}) {
7379
const user = await this.findByUsername(username);
7480
return this.userModel.delete({
81+
omit: {
82+
hashedPassword: true
83+
},
7584
where: { AND: [accessibleQuery(ability, 'delete', 'User')], id: user.id }
7685
});
7786
}
7887

7988
async find({ groupId }: { groupId?: string } = {}, { ability }: EntityOperationOptions = {}) {
8089
return this.userModel.findMany({
90+
omit: {
91+
hashedPassword: true
92+
},
8193
where: {
8294
AND: [accessibleQuery(ability, 'read', 'User'), { groupIds: groupId ? { has: groupId } : undefined }]
8395
}
@@ -86,6 +98,9 @@ export class UsersService {
8698

8799
async findById(id: string, { ability }: EntityOperationOptions = {}) {
88100
const user = await this.userModel.findFirst({
101+
omit: {
102+
hashedPassword: true
103+
},
89104
where: { AND: [accessibleQuery(ability, 'read', 'User')], id }
90105
});
91106
if (!user) {
@@ -97,6 +112,9 @@ export class UsersService {
97112
async findByUsername(username: string, { ability }: EntityOperationOptions = {}) {
98113
const user = await this.userModel.findFirst({
99114
include: { groups: true },
115+
omit: {
116+
hashedPassword: true
117+
},
100118
where: { AND: [accessibleQuery(ability, 'read', 'User'), { username }] }
101119
});
102120
if (!user) {
@@ -113,6 +131,9 @@ export class UsersService {
113131
connect: groupIds?.map((id) => ({ id }))
114132
}
115133
},
134+
omit: {
135+
hashedPassword: true
136+
},
116137
where: { AND: [accessibleQuery(ability, 'update', 'User')], id }
117138
});
118139
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opendatacapture",
33
"type": "module",
4-
"version": "1.9.3",
4+
"version": "1.9.4",
55
"private": true,
66
"packageManager": "[email protected]",
77
"license": "Apache-2.0",

packages/demo/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { deepFreeze } from '@douglasneuroinformatics/libjs';
22
import type { CreateGroupData } from '@opendatacapture/schemas/group';
33
import type { User } from '@opendatacapture/schemas/user';
44

5-
type DemoUser = Pick<User, 'basePermissionLevel' | 'firstName' | 'lastName' | 'password' | 'username'> & {
5+
type DemoUser = Pick<User, 'basePermissionLevel' | 'firstName' | 'lastName' | 'username'> & {
66
groupNames: readonly string[];
7+
password: string;
78
};
89

910
type DemoGroup = CreateGroupData & { dummyIdPrefix?: string };

packages/schemas/src/user/user.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const $User = $BaseModel.extend({
2323
firstName: z.string().min(1),
2424
groupIds: z.array(z.string()),
2525
lastName: z.string().min(1),
26-
password: z.string().min(1),
2726
sex: $Sex.nullish(),
2827
username: z.string().min(1)
2928
});
@@ -35,11 +34,11 @@ export const $CreateUserData = $User
3534
firstName: true,
3635
groupIds: true,
3736
lastName: true,
38-
password: true,
3937
username: true
4038
})
4139
.extend({
4240
dateOfBirth: z.coerce.date().optional(),
41+
password: z.string().min(1),
4342
sex: $Sex.optional()
4443
});
4544

0 commit comments

Comments
 (0)