@accounts/two-factor
Advanced tools
Comparing version 0.5.0-alpha.1 to 0.5.1-alpha.1
@@ -1,7 +0,2 @@ | ||
export declare const errors: { | ||
userNotFound: string; | ||
codeDidNotMatch: string; | ||
userTwoFactorNotSet: string; | ||
userTwoFactorAlreadySet: string; | ||
codeRequired: string; | ||
}; | ||
import { ErrorMessages } from './types'; | ||
export declare const errors: ErrorMessages; |
@@ -55,2 +55,3 @@ "use strict"; | ||
window: 0, | ||
errors: errors_1.errors, | ||
}; | ||
@@ -77,3 +78,3 @@ var TwoFactor = /** @class */ (function () { | ||
if (!code) { | ||
throw new Error(errors_1.errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -83,3 +84,3 @@ twoFactorService = utils_1.getUserTwoFactorService(user); | ||
if (!twoFactorService) { | ||
throw new Error(errors_1.errors.userTwoFactorNotSet); | ||
throw new Error(this.options.errors.userTwoFactorNotSet); | ||
} | ||
@@ -92,3 +93,3 @@ if (!speakeasy.totp.verify({ | ||
})) { | ||
throw new Error(errors_1.errors.codeDidNotMatch); | ||
throw new Error(this.options.errors.codeDidNotMatch); | ||
} | ||
@@ -120,3 +121,3 @@ return [2 /*return*/]; | ||
if (!code) { | ||
throw new Error(errors_1.errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -127,3 +128,3 @@ return [4 /*yield*/, this.db.findUserById(userId)]; | ||
if (!user) { | ||
throw new Error(errors_1.errors.userNotFound); | ||
throw new Error(this.options.errors.userNotFound); | ||
} | ||
@@ -133,3 +134,3 @@ twoFactorService = utils_1.getUserTwoFactorService(user); | ||
if (twoFactorService) { | ||
throw new Error(errors_1.errors.userTwoFactorAlreadySet); | ||
throw new Error(this.options.errors.userTwoFactorAlreadySet); | ||
} | ||
@@ -149,3 +150,3 @@ if (!speakeasy.totp.verify({ | ||
return [3 /*break*/, 4]; | ||
case 3: throw new Error(errors_1.errors.codeDidNotMatch); | ||
case 3: throw new Error(this.options.errors.codeDidNotMatch); | ||
case 4: return [2 /*return*/]; | ||
@@ -166,3 +167,3 @@ } | ||
if (!code) { | ||
throw new Error(errors_1.errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -173,3 +174,3 @@ return [4 /*yield*/, this.db.findUserById(userId)]; | ||
if (!user) { | ||
throw new Error(errors_1.errors.userNotFound); | ||
throw new Error(this.options.errors.userNotFound); | ||
} | ||
@@ -179,3 +180,3 @@ twoFactorService = utils_1.getUserTwoFactorService(user); | ||
if (!twoFactorService) { | ||
throw new Error(errors_1.errors.userTwoFactorNotSet); | ||
throw new Error(this.options.errors.userTwoFactorNotSet); | ||
} | ||
@@ -191,3 +192,3 @@ if (speakeasy.totp.verify({ | ||
else { | ||
throw new Error(errors_1.errors.codeDidNotMatch); | ||
throw new Error(this.options.errors.codeDidNotMatch); | ||
} | ||
@@ -194,0 +195,0 @@ return [2 /*return*/]; |
export { AccountsTwoFactorOptions } from './options'; | ||
export { TwoFactorService } from './two-factor-service'; | ||
export { ErrorMessages } from './error-messages'; |
@@ -0,5 +1,16 @@ | ||
import { ErrorMessages } from './error-messages'; | ||
export interface AccountsTwoFactorOptions { | ||
/** | ||
* Two factor app name | ||
*/ | ||
appName?: string; | ||
/** | ||
* Two factor secret length, default to 20 | ||
*/ | ||
secretLength?: number; | ||
window?: number; | ||
/** | ||
* Two factor module errors | ||
*/ | ||
errors?: ErrorMessages; | ||
} |
{ | ||
"name": "@accounts/two-factor", | ||
"version": "0.5.0-alpha.1", | ||
"version": "0.5.1-alpha.1", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/types": "^0.5.0-alpha.1", | ||
"@accounts/types": "^0.5.1-alpha.1", | ||
"@types/lodash": "^4.14.117", | ||
@@ -34,0 +34,0 @@ "@types/speakeasy": "2.0.2", |
@@ -1,2 +0,4 @@ | ||
export const errors = { | ||
import { ErrorMessages } from './types'; | ||
export const errors: ErrorMessages = { | ||
userNotFound: 'User not found', | ||
@@ -3,0 +5,0 @@ codeDidNotMatch: `2FA code didn't match`, |
@@ -10,6 +10,7 @@ import * as speakeasy from 'speakeasy'; | ||
window: 0, | ||
errors, | ||
}; | ||
export class TwoFactor { | ||
private options: AccountsTwoFactorOptions; | ||
private options: AccountsTwoFactorOptions & typeof defaultOptions; | ||
private db!: DatabaseInterface; | ||
@@ -34,3 +35,3 @@ private serviceName = 'two-factor'; | ||
if (!code) { | ||
throw new Error(errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -41,3 +42,3 @@ | ||
if (!twoFactorService) { | ||
throw new Error(errors.userTwoFactorNotSet); | ||
throw new Error(this.options.errors.userTwoFactorNotSet); | ||
} | ||
@@ -52,3 +53,3 @@ if ( | ||
) { | ||
throw new Error(errors.codeDidNotMatch); | ||
throw new Error(this.options.errors.codeDidNotMatch); | ||
} | ||
@@ -74,3 +75,3 @@ } | ||
if (!code) { | ||
throw new Error(errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -80,3 +81,3 @@ | ||
if (!user) { | ||
throw new Error(errors.userNotFound); | ||
throw new Error(this.options.errors.userNotFound); | ||
} | ||
@@ -86,3 +87,3 @@ let twoFactorService = getUserTwoFactorService(user); | ||
if (twoFactorService) { | ||
throw new Error(errors.userTwoFactorAlreadySet); | ||
throw new Error(this.options.errors.userTwoFactorAlreadySet); | ||
} | ||
@@ -103,3 +104,3 @@ | ||
} else { | ||
throw new Error(errors.codeDidNotMatch); | ||
throw new Error(this.options.errors.codeDidNotMatch); | ||
} | ||
@@ -113,3 +114,3 @@ } | ||
if (!code) { | ||
throw new Error(errors.codeRequired); | ||
throw new Error(this.options.errors.codeRequired); | ||
} | ||
@@ -119,3 +120,3 @@ | ||
if (!user) { | ||
throw new Error(errors.userNotFound); | ||
throw new Error(this.options.errors.userNotFound); | ||
} | ||
@@ -125,3 +126,3 @@ const twoFactorService = getUserTwoFactorService(user); | ||
if (!twoFactorService) { | ||
throw new Error(errors.userTwoFactorNotSet); | ||
throw new Error(this.options.errors.userTwoFactorNotSet); | ||
} | ||
@@ -138,5 +139,5 @@ if ( | ||
} else { | ||
throw new Error(errors.codeDidNotMatch); | ||
throw new Error(this.options.errors.codeDidNotMatch); | ||
} | ||
} | ||
} |
export { AccountsTwoFactorOptions } from './options'; | ||
export { TwoFactorService } from './two-factor-service'; | ||
export { ErrorMessages } from './error-messages'; |
@@ -0,7 +1,17 @@ | ||
import { ErrorMessages } from './error-messages'; | ||
export interface AccountsTwoFactorOptions { | ||
// Two factor app name | ||
/** | ||
* Two factor app name | ||
*/ | ||
appName?: string; | ||
// Two factor secret length, default to 20 | ||
/** | ||
* Two factor secret length, default to 20 | ||
*/ | ||
secretLength?: number; | ||
window?: number; | ||
/** | ||
* Two factor module errors | ||
*/ | ||
errors?: ErrorMessages; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129939
62
1163
+ Added@accounts/types@0.5.1-alpha.1(transitive)
- Removed@accounts/types@0.5.0-alpha.1(transitive)