| @@ -30,25 +30,22 @@ tokenSchema.statics.findByCredentials = async (email, password) => { | |||
| tokenSchema.statics.generateAuthToken = async function(userArg) { | |||
| const user = userArg | |||
| const token = jwt.sign({ _id: user._id.toString() }, 'ovoJeSecret', { expiresIn: 60 * 20 }) | |||
| const newToken = new Token({ token: token, userId: user._id }) | |||
| await newToken.save() | |||
| user.tokens = user.tokens.concat({ token: newToken }) | |||
| user.tokens = user.tokens.concat({ token }) | |||
| await user.save() | |||
| console.log(newToken) | |||
| return token | |||
| } | |||
| tokenSchema.statics.refreshAuthToken = async function(token, refreshOptions) { | |||
| const payload = jwt.verify(token, 'ovoJeSecret', refreshOptions.verify); | |||
| delete payload.iat; | |||
| delete payload.exp; | |||
| delete payload.nbf; | |||
| delete payload.jti; | |||
| const jwtSignOptions = Object.assign({ }, this.options, { jwtid: refreshOptions.jwtid }); | |||
| return jwt.sign(payload, this.secretOrPrivateKey, jwtSignOptions); | |||
| const payload = jwt.verify(token, 'ovoJeSecret', refreshOptions.verify) | |||
| delete payload.iat | |||
| delete payload.exp | |||
| delete payload.nbf | |||
| delete payload.jti | |||
| const jwtSignOptions = Object.assign({ }, this.options, { jwtid: refreshOptions.jwtid }) | |||
| return jwt.sign(payload, this.secretOrPrivateKey, jwtSignOptions) | |||
| } | |||
| const Token = mongoose.model('Token', tokenSchema) | |||