Video 112: Hiding Private Data
This commit is contained in:
parent
bae66dbf89
commit
db05569296
@ -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()
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user