-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: emit event to backend only if csr is absent in csrs list
- Loading branch information
Showing
2 changed files
with
12 additions
and
2 deletions.
There are no files selected for viewing
13 changes: 11 additions & 2 deletions
13
packages/state-manager/src/sagas/identity/saveUserCsr/saveUserCsr.saga.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import { SaveCSRPayload, SocketActionTypes } from '@quiet/types' | ||
import { applyEmitParams, type Socket } from '../../../types' | ||
import { apply, select } from 'typed-redux-saga' | ||
import { apply, call, select } from 'typed-redux-saga' | ||
import { identitySelectors } from '../identity.selectors' | ||
import { usersSelectors } from '../../users/users.selectors' | ||
import { keyFromCertificate, parseCertificationRequest } from '@quiet/identity' | ||
|
||
export function* saveUserCsrSaga(socket: Socket): Generator { | ||
const identity = yield* select(identitySelectors.currentIdentity) | ||
if (!identity?.userCsr) { | ||
console.error('Cannot save user csr to backend, no userCsr') | ||
return | ||
} | ||
|
||
// Because we run this saga everytime we launch community (to make sure that our csr is saved to db) we need below logic to avoid duplicates of csrs in the csr database. | ||
const parsedCsr = parseCertificationRequest(identity.userCsr.userCsr) | ||
const pubKey = yield* call(keyFromCertificate, parsedCsr) | ||
const csrs = yield* select(usersSelectors.csrsMapping) | ||
if (Object.keys(csrs).includes(pubKey)) return | ||
|
||
const payload: SaveCSRPayload = { | ||
csr: identity.userCsr?.userCsr, | ||
} | ||
console.log(`Send ${SocketActionTypes.SAVE_USER_CSR}`) | ||
yield* apply(socket, socket.emit, applyEmitParams(SocketActionTypes.SAVE_USER_CSR, payload)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters