refactor(striker-ui-api): hoist encrypt password

main
Tsu-ba-me 2 years ago
parent a16d5160d4
commit b080d319af
  1. 10
      striker-ui-api/src/lib/accessModule.ts
  2. 16
      striker-ui-api/src/middlewares/passport.ts
  3. 15
      striker-ui-api/src/types/EncryptFunction.d.ts

@ -246,6 +246,15 @@ const refreshTimestamp = () => {
return result;
};
const encrypt: EncryptFunction = async (params) => {
const [result]: [Encrypted] = await subroutine('encrypt_password', {
params: [params],
pre: ['Account'],
});
return result;
};
const getData = async <T>(...keys: string[]) => {
const chain = `data->${keys.join('->')}`;
@ -379,6 +388,7 @@ export {
insertOrUpdateVariable as variable,
anvilSyncShared,
refreshTimestamp as timestamp,
encrypt,
getData,
getAnvilData,
getFenceSpec,

@ -3,7 +3,7 @@ import { Strategy as LocalStrategy } from 'passport-local';
import { DELETED } from '../lib/consts';
import { query, sub } from '../lib/accessModule';
import { encrypt, query } from '../lib/accessModule';
import { sanitize } from '../lib/sanitize';
import { stdout } from '../lib/shell';
@ -47,24 +47,14 @@ passport.use(
0: [userUuid, , userPasswordHash, userSalt, userAlgorithm, userHashCount],
} = rows;
let encryptResult: {
user_password_hash: string;
user_salt: string;
user_hash_count: number;
user_algorithm: string;
};
let encryptResult: Encrypted;
try {
[encryptResult] = await sub('encrypt_password', {
params: [
{
encryptResult = await encrypt({
algorithm: userAlgorithm,
hash_count: userHashCount,
password,
salt: userSalt,
},
],
pre: ['Account'],
});
} catch (subError) {
return done(subError);

@ -0,0 +1,15 @@
type EncryptParams = SubroutineCommonParams & {
algorithm?: string;
hash_count?: string;
password: string;
salt?: string;
};
type Encrypted = {
user_algorithm: string;
user_hash_count: number;
user_password_hash: string;
user_salt: string;
};
type EncryptFunction = (params: EncryptParams) => Promise<Encrypted>;
Loading…
Cancel
Save