diff --git a/src/models/User.ts b/src/models/User.ts index 81b321a..13fe2d9 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -19,10 +19,12 @@ export type UserModel = mongoose.Document & { picture: string }, - comparePassword: (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void, + comparePassword: comparePasswordFunction, gravatar: (size: number) => string }; +type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; + export type AuthToken = { accessToken: string, kind: string @@ -64,12 +66,13 @@ userSchema.pre("save", function save(next) { }); }); -userSchema.methods.comparePassword = function (candidatePassword: string, cb: (err: any, isMatch: any) => {}) { +const comparePassword: comparePasswordFunction = function (candidatePassword, cb) { bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => { cb(err, isMatch); }); }; +userSchema.methods.comparePassword = comparePassword; /** * Helper method for getting user's gravatar. @@ -87,4 +90,4 @@ userSchema.methods.gravatar = function (size: number) { // export const User: UserType = mongoose.model('User', userSchema); const User = mongoose.model("User", userSchema); -export default User; \ No newline at end of file +export default User;