UserSchema.methods.generateAuthToken = function () {
var user = this;
var access = 'auth';
var token = jwt.sign({_id: user._id.toHexString(), access}, 'abc123').toString();
user.tokens.push({access, token});
return user.save().then(() => {
return token;
});
};
var User = mongoose.model('User', UserSchema);
module.exports = {User}