Skip to content

Commit 0fd11d0

Browse files
committed
fix(auth): ensure roles are initialized for API keys before modification
Added checks to initialize the roles array for API keys if it is undefined, preventing potential errors when adding or removing roles. This change enhances the robustness of the role management functionality in the AuthService.
1 parent f7f75e9 commit 0fd11d0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

api/src/unraid-api/auth/auth.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export class AuthService {
201201
}
202202

203203
try {
204+
if (!apiKey.roles) {
205+
apiKey.roles = [];
206+
}
204207
if (!apiKey.roles.includes(role)) {
205208
apiKey.roles.push(role);
206209
await this.apiKeyService.saveApiKey(apiKey);
@@ -225,6 +228,9 @@ export class AuthService {
225228
}
226229

227230
try {
231+
if (!apiKey.roles) {
232+
apiKey.roles = [];
233+
}
228234
apiKey.roles = apiKey.roles.filter((r) => r !== role);
229235
await this.apiKeyService.saveApiKey(apiKey);
230236
await this.authzService.deleteRoleForUser(apiKeyId, role);

0 commit comments

Comments
 (0)