fix: API key regeneration fails when roles feature is disabled (#13588)
This commit is contained in:
+9
-2
@@ -156,19 +156,26 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
name: string,
|
||||
newExpiresAt: string | null,
|
||||
) => {
|
||||
if (!selectedRoleId) {
|
||||
const adminRole = roles.find((role) => role.label === 'Admin');
|
||||
const roleIdToUse = isApiKeyRolesEnabled ? selectedRoleId : adminRole?.id;
|
||||
|
||||
if (!roleIdToUse && isApiKeyRolesEnabled) {
|
||||
enqueueErrorSnackBar({
|
||||
message: t`A role must be selected for the API key`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!roleIdToUse) {
|
||||
throw new Error('Admin role not found - this should never happen');
|
||||
}
|
||||
|
||||
const { data: newApiKeyData } = await createApiKey({
|
||||
variables: {
|
||||
input: {
|
||||
name: name,
|
||||
expiresAt: newExpiresAt ?? '',
|
||||
roleId: selectedRoleId,
|
||||
roleId: roleIdToUse,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user