Skip to content

Commit cc63777

Browse files
authored
fix: delete user.collective after OTP fails (#11237)
1 parent 4d05095 commit cc63777

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

server/models/User.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
484484

485485
const destroyInTransaction = async transaction => {
486486
await this.update({ email: newEmail }, { transaction });
487+
const collective = await Collective.findByPk(this.CollectiveId, { transaction });
488+
if (collective) {
489+
await collective.destroy({ transaction });
490+
}
487491
return this.destroy({ transaction });
488492
};
489493

test/server/controllers/users.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ describe('server/controllers/users', () => {
346346
const otpSessionKey = `otp_signup_${email}`;
347347
let otpSession = await sessionCache.get(otpSessionKey);
348348
expect(otpSession).to.exist;
349+
const userId = otpSession.userId;
349350

350351
let verifyResponse = await makeVerifyOtpRequest(email, '023456', responseData.sessionId, randIPV4());
351352
expect(verifyResponse._getStatusCode()).to.eql(403);
@@ -362,8 +363,12 @@ describe('server/controllers/users', () => {
362363
expect(verifyResponse._getStatusCode()).to.eql(403);
363364
otpSession = await sessionCache.get(otpSessionKey);
364365
expect(otpSession).to.be.undefined;
365-
const user = await models.User.findOne({ where: { email } });
366-
expect(user).to.be.null;
366+
const user = await models.User.findByPk(userId, {
367+
include: [{ model: models.Collective, as: 'collective', paranoid: false }],
368+
paranoid: false,
369+
});
370+
expect(user.deletedAt).not.to.be.null;
371+
expect(user.collective.deletedAt).not.to.be.null;
367372
});
368373
});
369374
});

0 commit comments

Comments
 (0)