1
0
Fork 0

Video 112: Hiding Private Data

This commit is contained in:
JayWll 2020-07-15 16:10:24 -06:00
parent bae66dbf89
commit db05569296
2 changed files with 10 additions and 12 deletions

View File

@ -25,15 +25,3 @@ app.use(taskRouter)
app.listen(port, () => {
console.log('Server is up on port ' + port)
})
const jwt = require('jsonwebtoken')
const myFunction = async () => {
const token = jwt.sign({ _id: 'abc123' }, 'thisismynewcourse', { expiresIn: '7 days' })
console.log(token)
const data = jwt.verify(token, 'thisismynewcourse')
console.log(data)
}
myFunction()

View File

@ -49,6 +49,16 @@ const userSchema = new mongoose.Schema({
}]
})
userSchema.methods.toJSON = function() {
const user = this
const userObject = user.toObject()
delete userObject.password
delete userObject.tokens
return userObject
}
userSchema.methods.generateAuthToken = async function () {
const user = this
const token = jwt.sign({ _id: user._id.toString() }, 'thisismynewcourse')