- 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:
Paolo Arena
2019-02-11 02:59:05 +01:00
parent 636ee92786
commit d24b232a2d
7 changed files with 437 additions and 370 deletions

View File

@@ -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,
});
};