Skip to content

Commit c0dee8d

Browse files
authored
fix: Allow TOTP 2FA without email verification (#37368)
1 parent c390d5c commit c0dee8d

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

.changeset/dull-deers-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': minor
3+
---
4+
5+
Allows users to enable TOTP-based two factor authentication without requiring a verified email address.

apps/meteor/app/2fa/server/methods/enable.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ Meteor.methods<ServerMethods>({
2626
});
2727
}
2828

29-
const hasUnverifiedEmail = user.emails?.some((email) => !email.verified);
30-
31-
if (hasUnverifiedEmail) {
32-
throw new Meteor.Error('error-invalid-user', 'You need to verify your emails before setting up 2FA', {
33-
method: '2fa:enable',
34-
});
35-
}
36-
3729
if (user.services?.totp?.enabled) {
3830
throw new Meteor.Error('error-2fa-already-enabled');
3931
}

apps/meteor/tests/end-to-end/api/methods/2fa-enable.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('2fa:enable', function () {
5252
});
5353
});
5454

55-
it('should return error when user is not verified', async () => {
55+
it('should return secret and qr code url even when user has unverified email', async () => {
5656
await request
5757
.post(methodCall('2fa:enable'))
5858
.set(user3Credentials)
@@ -66,10 +66,14 @@ describe('2fa:enable', function () {
6666
})
6767
.expect(200)
6868
.expect((res) => {
69-
expect(res.body).to.have.property('message');
70-
const result = JSON.parse(res.body.message);
71-
expect(result).to.have.property('error');
72-
expect(result.error).to.not.have.property('errpr', 'error-invalid-user');
69+
expect(res.body).to.have.property('success', true);
70+
const parsedBody = JSON.parse(res.body.message);
71+
expect(parsedBody).to.have.property('result');
72+
expect(parsedBody.result).to.have.property('secret').of.a('string');
73+
expect(parsedBody.result)
74+
.to.have.property('url')
75+
.of.a('string')
76+
.match(/^otpauth:\/\//);
7377
});
7478
});
7579

0 commit comments

Comments
 (0)