fix: API key regeneration fails when roles feature is disabled (#13588)

This commit is contained in:
nitin
2025-08-04 16:38:51 +05:30
committed by GitHub
parent 5c7c8d1bba
commit b85918fc7a
@@ -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,
},
},
});