Skip to content

Instantly share code, notes, and snippets.

@jepetko
Created March 15, 2019 13:58
Show Gist options
  • Save jepetko/48049d4e2df5906f44c7c8db71d1545f to your computer and use it in GitHub Desktop.
Save jepetko/48049d4e2df5906f44c7c8db71d1545f to your computer and use it in GitHub Desktop.
FeathersJS Authentication User Factory
import * as bcrypt from 'bcryptjs';
const hashPassword = (pwd) => {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(pwd, salt);
};
export const DEFAULT_PASSWORD = 'pwd';
export function defineUserFactory(factory, model) {
if (factory.factories.unverifiedUser) {
return;
}
factory.define('unverifiedUser', model, {
email: factory.sequence('User.email', (i: number) => `user@domain-${i}.at`),
password: () => hashPassword(DEFAULT_PASSWORD),
isVerified: false
});
factory.extend('unverifiedUser', 'verifiedUser', {
isVerified: true,
verifyToken: null,
verifyShortToken: null,
verifyExpires: null
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment