Skip to content

Commit

Permalink
ensure csr is saved when updating username
Browse files Browse the repository at this point in the history
  • Loading branch information
adrastaea committed Oct 25, 2024
1 parent a80ab2e commit 0cad2d4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
}
}
1 change: 1 addition & 0 deletions packages/types/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface IdentityUpdatePayload {
export interface InitUserCsrPayload {
communityId: string
nickname: string
isUsernameTaken?: boolean
}

export interface CreateUserCsrPayload {
Expand Down

0 comments on commit 0cad2d4

Please sign in to comment.