Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Med5KDB committed Jul 21, 2024
1 parent 2791f95 commit 23785f0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
66 changes: 41 additions & 25 deletions src/keycloak-user-manager/keycloak-user-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ export class KeycloakUserManagerService {

async createUser(data: UserCreateInput): Promise<User> {
const { firstName, lastName, username, email, password } = data;
const createdUser = await this.kcAdminClientProvider.users.create({
firstName,
lastName,
username,
email,
enabled: true,
credentials: [{ type: 'password', value: password, temporary: true }],
});
const createdUser = await this.kcAdminClientProvider
.getkCAdminClient()
.users.create({
firstName,
lastName,
username,
email,
enabled: true,
credentials: [{ type: 'password', value: password, temporary: true }],
});
const userId = createdUser.id;
const fullUser = await this.kcAdminClientProvider.users.findOne({
id: userId,
});
const fullUser = await this.kcAdminClientProvider
.getkCAdminClient()
.users.findOne({
id: userId,
});
if (!fullUser) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
Expand All @@ -42,7 +46,7 @@ export class KeycloakUserManagerService {
data: UserUpdateInput,
): Promise<User> {
const { firstName, lastName, username, email } = data;
await this.kcAdminClientProvider.users.update(
await this.kcAdminClientProvider.getkCAdminClient().users.update(
{
id: where.id,
},
Expand All @@ -54,47 +58,57 @@ export class KeycloakUserManagerService {
},
);
const userId = where.id;
const fullUser = await this.kcAdminClientProvider.users.findOne({
id: userId,
});
const fullUser = await this.kcAdminClientProvider
.getkCAdminClient()
.users.findOne({
id: userId,
});
if (!fullUser) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
return this.mapKeycloakUserToUser(fullUser);
}
async deleteUser(where: UserWhereUniqueInput): Promise<{ id: string }> {
await this.kcAdminClientProvider.users.del({ id: where.id });
await this.kcAdminClientProvider
.getkCAdminClient()
.users.del({ id: where.id });
return { id: where.id };
}

async findUserById(where: UserWhereUniqueInput): Promise<User> {
const userId = where.id;
const fullUser = await this.kcAdminClientProvider.users.findOne({
id: userId,
});
const fullUser = await this.kcAdminClientProvider
.getkCAdminClient()
.users.findOne({
id: userId,
});
if (!fullUser) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
return this.mapKeycloakUserToUser(fullUser);
}

async findManyUsers(): Promise<User[]> {
const users = await this.kcAdminClientProvider.users.find();
const users = await this.kcAdminClientProvider
.getkCAdminClient()
.users.find();
return Promise.all(
users.map(async (user) => this.mapKeycloakUserToUser(user)),
);
}

async countUsers(): Promise<number> {
const users = await this.kcAdminClientProvider.users.find();
const users = await this.kcAdminClientProvider
.getkCAdminClient()
.users.find();
return users.length;
}

async resetUserPassword(
resetUserPasswordInput: ResetUserPasswordInput,
): Promise<User> {
const { id, password } = resetUserPasswordInput;
await this.kcAdminClientProvider.users.resetPassword({
await this.kcAdminClientProvider.getkCAdminClient().users.resetPassword({
id,
credential: {
type: 'password',
Expand All @@ -103,9 +117,11 @@ export class KeycloakUserManagerService {
},
});
const userId = id;
const fullUser = await this.kcAdminClientProvider.users.findOne({
id: userId,
});
const fullUser = await this.kcAdminClientProvider
.getkCAdminClient()
.users.findOne({
id: userId,
});
if (!fullUser) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
Expand Down
3 changes: 3 additions & 0 deletions src/providers/kc-admin-client.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ export class KCAdminClientProvider {
clientSecret: this.configOptions.clientSecret,
});
}
getkCAdminClient() {
return this.KeycloakAdminClient;
}
}

0 comments on commit 23785f0

Please sign in to comment.