Created
November 21, 2020 00:05
-
-
Save Cool-sami12/eaa398a4bdb46aca3c6ddd50cf47946f to your computer and use it in GitHub Desktop.
question about static schema in a model
This file contains hidden or 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
| // // find by token | |
| // userSchema.statics.findByToken = function(token,cb){ | |
| // var user = this; | |
| // var SECRET= process.env.SECRET; | |
| // jwt.verify(token,SECRET,function(err,decode){ | |
| // user.findone({"_id": decode, "token":token},function(err,user){ | |
| // if(err) return cb(err); | |
| // cb(null,user); | |
| // }) | |
| // }) | |
| // }; | |
| userSchema.methods.generateAuthToken = async function() { | |
| // Generate an auth token for the user | |
| const user = this | |
| const token = jwt.sign({_id: user._id}, process.env.SECRET) | |
| user.tokens = user.tokens.concat({token}) | |
| await user.save() | |
| return token | |
| } | |
| // userSchema.statics.findByCredentials = async (email, password) => { | |
| // // Search for a user by email and password. | |
| // const user = await User.findOne({ email} ) | |
| // if (!user) { | |
| // throw new Error({ error: 'Invalid login credentials' }) | |
| // } | |
| // const isPasswordMatch = await bcrypt.compare(password, user.password) | |
| // if (!isPasswordMatch) { | |
| // throw new Error({ error: 'Invalid login credentials' }) | |
| // } | |
| // return user | |
| // } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment