Skip to content

Commit cef806c

Browse files
committed
fix: allow fetching rosters
1 parent 542675f commit cef806c

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/auth/auth.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ export class AuthService {
5353
userId: user.userId,
5454
roles: user.roles,
5555
accessToken: this.createJwt(
56-
{ userId: user.userId, roles: user.roles, username: user.username },
56+
{
57+
userId: user.userId,
58+
roles: user.roles,
59+
username: user.username,
60+
guildIds: user.guildIds,
61+
},
5762
{ expiresIn: '2h' },
5863
),
5964
};
@@ -145,6 +150,7 @@ export class AuthService {
145150
userId: input.userId,
146151
roles: input.roles,
147152
username: dto.displayName,
153+
guildIds: dto.guildIds,
148154
}),
149155
};
150156
}
@@ -227,15 +233,21 @@ export class AuthService {
227233
}
228234

229235
private createJwt(
230-
input: { userId: string; roles: UserRoles[]; username: string; remoteIp?: string },
236+
input: {
237+
userId: string;
238+
roles: UserRoles[];
239+
username: string;
240+
remoteIp?: string;
241+
guildIds?: string[];
242+
},
231243
options?: JwtSignOptions,
232244
) {
233245
const payload = {
234246
userId: input.userId,
235247
roles: input.roles,
236248
version: '1',
237249
jti: randomUUID(),
238-
guildIds: [],
250+
guildIds: input.guildIds || [],
239251
remoteIp: input.remoteIp,
240252
username: input.username.toLowerCase(),
241253
} satisfies JwtUserInput;

src/auth/dto/user-roles.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export enum UserRoles {
1212
FETCH_LINKS = 'fetch:links',
1313
MANAGE_LINKS = 'manage:links',
1414

15+
FETCH_ROSTERS = 'fetch:rosters',
16+
1517
MANAGE_ROSTERS = 'manage:rosters',
1618

1719
MANAGE_REMINDERS = 'manage:reminders',

src/db/collections/api-users.entity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export class ApiUsersEntity {
99
username: string;
1010
createdAt: Date;
1111
updatedAt: Date;
12+
guildIds: string[];
1213
deletedAt: Date | null;
1314
}

src/rosters/rosters.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class RostersController {
3131
constructor(private rostersService: RostersService) {}
3232

3333
@Get('/:guildId/list')
34+
@Roles([UserRoles.USER, UserRoles.FETCH_ROSTERS])
3435
getRosters(@Param('guildId') guildId: string): Promise<GetRostersDto> {
3536
return this.rostersService.getRosters(guildId);
3637
}

0 commit comments

Comments
 (0)