Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // /imports/api/methods/twoFactorAuth.js
- import SimpleSchema from 'simpl-schema';
- export const TwoFactorToken = {
- type: SimpleSchema.Integer, min: 0, max: 999999, optional: true,
- };
- export const tokenIsValid = (token: string, secret: string) => {
- if (!authenticator.check(token, secret)) {
- throw new Meteor.Error('twoFactor.invalid-token');
- }
- };
- export const enableTwoFactor = new ValidatedMethod({
- name: 'twoFactor.enableTwoFactor',
- validate: new SimpleSchema({
- token: TwoFactorToken,
- }).validator(),
- run({ token }) {
- userIsLoggedIn(this.userId);
- if (this.isSimulation) return;
- tokenIsValid(token, Meteor.user().services.twoFactorSecret);
- Meteor.users.update(this.userId, { $set: { twoFactorEnabled: true } });
- },
- });
Add Comment
Please, Sign In to add comment