@tomei/sso 0.55.0 → 0.56.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ module.exports = {
10
10
  });
11
11
 
12
12
  await queryInterface.addColumn('sso_User', 'PasscodeUpdatedAt', {
13
- type: Sequelize.STRING(255),
13
+ type: Sequelize.DATE,
14
14
  });
15
15
 
16
16
  await transaction.commit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.55.0",
3
+ "version": "0.56.1",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -2868,4 +2868,44 @@ export class User extends UserBase {
2868
2868
  throw error;
2869
2869
  }
2870
2870
  }
2871
+
2872
+ async verifyPasscode(passcode: string) {
2873
+ try {
2874
+ // Return error if this._Userid is empty "User is not created yet."
2875
+ if (!this.UserId) {
2876
+ throw new ClassError(
2877
+ 'User',
2878
+ 'UserErrMsg0X',
2879
+ 'User is not created yet.',
2880
+ );
2881
+ }
2882
+ // Return error if this._PasscodeHash is empty. "Passcode has not been set yet."
2883
+ if (!this.PasscodeHash) {
2884
+ throw new ClassError(
2885
+ 'User',
2886
+ 'UserErrMsg0X',
2887
+ 'Passcode has not been set yet.',
2888
+ 'verifyPasscode',
2889
+ );
2890
+ }
2891
+ // Using the same password hash service during create passcode. Validate this._PasscodeHash with params.passcode. Return error if not matched. "Invalid passcode."
2892
+ const passwordHashService = new PasswordHashService();
2893
+ const isMatch = await passwordHashService.verify(
2894
+ passcode,
2895
+ this.PasscodeHash,
2896
+ );
2897
+
2898
+ if (!isMatch) {
2899
+ throw new ClassError(
2900
+ 'User',
2901
+ 'UserErrMsg0X',
2902
+ 'Invalid passcode.',
2903
+ 'verifyPasscode',
2904
+ 400,
2905
+ );
2906
+ }
2907
+ } catch (error) {
2908
+ throw error;
2909
+ }
2910
+ }
2871
2911
  }