Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var userSchema = new mongoose.Schema({
- ...
- auth: {
- password: String,
- passToken: String,
- tokenExpires: Date
- },
- ...
- });
- userSchema.methods.createToken = function(next){
- require('crypto').randomBytes(16, function(err,buf){
- if (err){ next(err); }
- else {
- this.auth.passToken = buf.toString('hex');
- this.auth.tokenExpires = Date.now() + 3600000;
- this.save();
- }
- });
- };
- /path/to/project/config/models.js:85
- this.auth.passToken = buf.toString('hex');
- ^
- TypeError: Cannot set property 'passToken' of undefined
- at InternalFieldObject.ondone (/path/to/project/config/models.js:85:25)
- userSchema.methods.createToken = function(next){
- var user = this;
- require('crypto').randomBytes(16, function(err,buf){
- if (err){ next(err); }
- else {
- user.auth.passToken = buf.toString('hex');
- user.auth.tokenExpires = Date.now() + 3600000;
- user.save();
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement