Skip to content

Commit

Permalink
feat: query keycloak to check for existing realm
Browse files Browse the repository at this point in the history
  • Loading branch information
NithinKuruba committed Dec 17, 2023
1 parent 308585e commit 967e401
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/pages/api/realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
});

if (existingRealm.length > 0) {
const kcCore = new KeycloakCore('prod');

const kcAdminClient = await kcCore.getAdminClient();

const existingKcRealms = await kcAdminClient.realms.find();

// the keycloak console may not show realm if the realm name was manually updated through console
// however the realm id does not change
if (existingRealm.length > 0 || existingKcRealms.find((realm) => realm.id === data.realm)) {
return res.status(400).json({ success: false, error: 'Realm name already taken' });
}

Expand Down

0 comments on commit 967e401

Please sign in to comment.