Created
March 15, 2019 13:58
-
-
Save jepetko/48049d4e2df5906f44c7c8db71d1545f to your computer and use it in GitHub Desktop.
FeathersJS Authentication User Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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