From 0cad2d417eefe0189887c6f0a7f30ada27e2f933 Mon Sep 17 00:00:00 2001 From: Taea Vogel Date: Fri, 25 Oct 2024 18:29:00 -0400 Subject: [PATCH] ensure csr is saved when updating username --- .../connections-manager.service.ts | 5 ++++- .../registerUsername/registerUsername.saga.ts | 12 ++++-------- packages/types/src/identity.ts | 1 + 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index 0e54f1a8a3..4c491d5426 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -460,7 +460,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI userCsr = await createUserCsr(createUserCsrPayload) } catch (e) { emitError(this.serverIoProvider.io, { - type: SocketActionTypes.ADD_CSR, + type: SocketActionTypes.CREATE_USER_CSR, message: ErrorMessages.USER_CSR_CREATION_FAILED, community: communityId, }) @@ -470,6 +470,9 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI identity = { ...identity, userCsr: userCsr, nickname: nickname } this.logger.info('Created user CSR') await this.storageService.setIdentity(identity) + if (payload.isUsernameTaken) { + await this.storageService.saveCSR({ csr: userCsr.userCsr }) + } return identity } diff --git a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.ts b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.ts index 78a0a4f361..c7cc68ed8e 100644 --- a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.ts +++ b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.ts @@ -32,7 +32,7 @@ export function* registerUsernameSaga( logger.info(`Found community ${community?.id} has CA?: ${community?.CA !== null}`) logger.info('Emitting CREATE_USER_CSR') - const payload: InitUserCsrPayload = { communityId: community.id, nickname: nickname } + const payload: InitUserCsrPayload = { communityId: community.id, nickname, isUsernameTaken } const identity: Identity = yield* apply( socket, socket.emitWithAck, @@ -43,12 +43,8 @@ export function* registerUsernameSaga( if (community.CA?.rootCertString) { yield* put(communitiesActions.createCommunity(community.id)) - } else { - if (!isUsernameTaken) { - logger.info('Username is not taken, launching community') - yield* put(communitiesActions.launchCommunity(community.id)) - } else { - yield* put(identityActions.saveUserCsr()) - } + } else if (!isUsernameTaken) { + logger.info('Username is not taken, launching community') + yield* put(communitiesActions.launchCommunity(community.id)) } } diff --git a/packages/types/src/identity.ts b/packages/types/src/identity.ts index 26a2fbf8ba..4682cba82a 100644 --- a/packages/types/src/identity.ts +++ b/packages/types/src/identity.ts @@ -47,6 +47,7 @@ export interface IdentityUpdatePayload { export interface InitUserCsrPayload { communityId: string nickname: string + isUsernameTaken?: boolean } export interface CreateUserCsrPayload {