Skip to content

Commit

Permalink
Using _id instead of username when querying in the users collection
Browse files Browse the repository at this point in the history
  • Loading branch information
denihs committed Mar 21, 2022
1 parent 87d03ed commit b82114e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/accounts-2fa/2fa-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ Meteor.methods({
);
}

const { username } = user;
const { _id, username, email } = user;

const { secret, uri } = twofactor.generateSecret({
name: appName.trim(),
account: username,
account: username || email,
});
const svg = new QRCode(uri).svg();

Meteor.users.update(
{ username },
{ _id },
{
$set: {
'services.twoFactorAuthentication': {
Expand All @@ -81,8 +81,8 @@ Meteor.methods({
}

const {
_id,
services: { twoFactorAuthentication },
username,
} = user;

if (!twoFactorAuthentication || !twoFactorAuthentication.secret) {
Expand All @@ -96,7 +96,7 @@ Meteor.methods({
}

Meteor.users.update(
{ username },
{ _id },
{
$set: {
'services.twoFactorAuthentication': {
Expand All @@ -115,7 +115,7 @@ Meteor.methods({
}

Meteor.users.update(
{ username: user.username },
{ _id: user._id },
{
$unset: {
'services.twoFactorAuthentication': 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-base/accounts_client_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const removeTestUser = done => {
};

const forceEnableUser2fa = done => {
Meteor.call('forceEnableUser2fa', username, secret2fa, (err, token) => {
Meteor.call('forceEnableUser2fa', { username }, secret2fa, (err, token) => {
done(token);
});
};
Expand Down
10 changes: 5 additions & 5 deletions packages/accounts-base/accounts_tests_setup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const getTokenFromSecret = ({ username, secret: secretParam }) => {
const getTokenFromSecret = ({ selector, secret: secretParam }) => {
let secret = secretParam;

if (!secret) {
const { services: { twoFactorAuthentication } = {} } =
Meteor.users.findOne({ username }) || {};
Meteor.users.findOne(selector) || {};
if (!twoFactorAuthentication) {
throw new Meteor.Error(500, 'twoFactorAuthentication not set.');
}
Expand All @@ -18,9 +18,9 @@ Meteor.methods({
removeAccountsTestUser(username) {
Meteor.users.remove({ username });
},
forceEnableUser2fa(username, secret) {
forceEnableUser2fa(selector, secret) {
Meteor.users.update(
{ username },
selector,
{
$set: {
'services.twoFactorAuthentication': {
Expand All @@ -30,7 +30,7 @@ Meteor.methods({
},
}
);
return getTokenFromSecret({ username, secret });
return getTokenFromSecret({ selector, secret });
},
getTokenFromSecret,
});

0 comments on commit b82114e

Please sign in to comment.