From a9bc3ab30b5a70ad1b9a581176b3179ec9c633d8 Mon Sep 17 00:00:00 2001 From: Adrian Kunz Date: Sun, 25 Aug 2024 18:04:53 +0200 Subject: [PATCH] fix(backend): Keycloak auth errors --- apps/backend/src/auth/keycloak.service.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/backend/src/auth/keycloak.service.ts b/apps/backend/src/auth/keycloak.service.ts index bcaf94a9..37bbcb26 100644 --- a/apps/backend/src/auth/keycloak.service.ts +++ b/apps/backend/src/auth/keycloak.service.ts @@ -12,13 +12,18 @@ export class KeycloakService { baseUrl: environment.keycloak.baseUrl, realmName: environment.keycloak.realmName, }); - await kcAdminClient.auth({ - grantType: 'password', - username: environment.keycloak.adminUser, - password: environment.keycloak.adminPassword, - clientId: environment.keycloak.clientId, - clientSecret: environment.keycloak.clientSecret, - }); + try { + await kcAdminClient.auth({ + grantType: 'password', + username: environment.keycloak.adminUser, + password: environment.keycloak.adminPassword, + clientId: environment.keycloak.clientId, + clientSecret: environment.keycloak.clientSecret, + }); + } catch (err) { + console.error(err); + return; + } return kcAdminClient.users.findOne({id}); } }