- fix: Date problems... (it was a bad "copy" function, the object date was not valid...)
- fix: error fetch on loading... (offline appeared)
This commit is contained in:
@@ -64,7 +64,10 @@ var UserSchema = new mongoose.Schema({
|
||||
token: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
date_login: {
|
||||
type: Date
|
||||
},
|
||||
}],
|
||||
date_tokenforgot: {
|
||||
type: Date
|
||||
@@ -91,10 +94,11 @@ UserSchema.methods.generateAuthToken = function (req) {
|
||||
|
||||
var access = 'auth ' + useragent;
|
||||
var token = jwt.sign({ _id: user._id.toHexString(), access }, process.env.SIGNCODE).toString();
|
||||
var date_login = new Date();
|
||||
|
||||
// CANCELLA IL PRECEDENTE !
|
||||
user.tokens = user.tokens.filter(function(tok) { return tok.access !== access; });
|
||||
user.tokens.push({ access, token });
|
||||
user.tokens.push({ access, token, date_login });
|
||||
|
||||
return user.save()
|
||||
.then(() => {
|
||||
@@ -119,7 +123,7 @@ UserSchema.statics.findByToken = function (token, typeaccess) {
|
||||
return User.findOne({
|
||||
'_id': decoded._id,
|
||||
'tokens.token': token,
|
||||
'tokens.access': typeaccess
|
||||
'tokens.access': typeaccess,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user