Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@accounts/two-factor

Package Overview
Dependencies
Maintainers
5
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/two-factor - npm Package Compare versions

Comparing version 0.1.0-beta.6 to 0.1.0-beta.7

20

lib/two-factor.d.ts

@@ -16,8 +16,28 @@ import * as speakeasy from 'speakeasy';

constructor(options?: AccountsTwoFactorOptions);
/**
* Set two factor store
*/
setStore(store: DatabaseInterface): void;
/**
* Return the user two factor service object
*/
getUserService: (user: User) => TwoFactorService;
/**
* Authenticate a user with a 2fa code
*/
authenticate(user: User, code: string): Promise<void>;
/**
* Generate a new two factor secret
*/
getNewAuthSecret(): speakeasy.Key;
/**
* Verify the code is correct
* Add the code to the user profile
* Throw if user already have 2fa enabled
*/
set(userId: string, secret: speakeasy.Key, code: string): Promise<void>;
/**
* Remove two factor for a user
*/
unset(userId: string, code: string): Promise<void>;
}

41

lib/two-factor.js

@@ -52,3 +52,3 @@ "use strict";

};
var TwoFactor = (function () {
var TwoFactor = /** @class */ (function () {
function TwoFactor(options) {

@@ -58,2 +58,5 @@ if (options === void 0) { options = {}; }

this.serviceName = 'two-factor';
/**
* Return the user two factor service object
*/
this.getUserService = function (user) {

@@ -64,5 +67,11 @@ return user.services[_this.serviceName];

}
/**
* Set two factor store
*/
TwoFactor.prototype.setStore = function (store) {
this.db = store;
};
/**
* Authenticate a user with a 2fa code
*/
TwoFactor.prototype.authenticate = function (user, code) {

@@ -76,2 +85,3 @@ return __awaiter(this, void 0, void 0, function () {

twoFactorService = this.getUserService(user);
// If user does not have 2fa set return error
if (!twoFactorService) {

@@ -88,6 +98,9 @@ throw new Error(errors_1.errors.userTwoFactorNotSet);

}
return [2];
return [2 /*return*/];
});
});
};
/**
* Generate a new two factor secret
*/
TwoFactor.prototype.getNewAuthSecret = function () {

@@ -99,2 +112,7 @@ return speakeasy.generateSecret({

};
/**
* Verify the code is correct
* Add the code to the user profile
* Throw if user already have 2fa enabled
*/
TwoFactor.prototype.set = function (userId, secret, code) {

@@ -109,3 +127,3 @@ return __awaiter(this, void 0, void 0, function () {

}
return [4, this.db.findUserById(userId)];
return [4 /*yield*/, this.db.findUserById(userId)];
case 1:

@@ -117,2 +135,3 @@ user = _a.sent();

twoFactorService = this.getUserService(user);
// If user already have 2fa return error
if (twoFactorService) {

@@ -126,12 +145,12 @@ throw new Error(errors_1.errors.userTwoFactorAlreadySet);

window: this.options.window,
})) return [3, 3];
})) return [3 /*break*/, 3];
twoFactorService = {
secret: secret,
};
return [4, this.db.setService(userId, this.serviceName, twoFactorService)];
return [4 /*yield*/, this.db.setService(userId, this.serviceName, twoFactorService)];
case 2:
_a.sent();
return [3, 4];
return [3 /*break*/, 4];
case 3: throw new Error(errors_1.errors.codeDidNotMatch);
case 4: return [2];
case 4: return [2 /*return*/];
}

@@ -141,2 +160,5 @@ });

};
/**
* Remove two factor for a user
*/
TwoFactor.prototype.unset = function (userId, code) {

@@ -151,3 +173,3 @@ return __awaiter(this, void 0, void 0, function () {

}
return [4, this.db.findUserById(userId)];
return [4 /*yield*/, this.db.findUserById(userId)];
case 1:

@@ -159,2 +181,3 @@ user = _a.sent();

twoFactorService = this.getUserService(user);
// If user does not have 2fa set return error
if (!twoFactorService) {

@@ -174,3 +197,3 @@ throw new Error(errors_1.errors.userTwoFactorNotSet);

}
return [2];
return [2 /*return*/];
}

@@ -177,0 +200,0 @@ });

{
"name": "@accounts/two-factor",
"version": "0.1.0-beta.6",
"version": "0.1.0-beta.7",
"license": "MIT",

@@ -31,8 +31,6 @@ "main": "lib/index.js",

"dependencies": {
"@accounts/types": "^0.1.0-beta.7",
"@types/speakeasy": "2.0.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"@accounts/types": "^0.1.0-beta.6",
"@types/speakeasy": "2.0.2"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc