UserModelVk.findOne({vkontakteId: profile.id}, function(err, vkUser){
if(err){ return done(err) }
if(!vkUser){
const user = new UserModelVk({
vkontakteId: profile.id,
name: profile.displayName,
access_token: params.access_token
})
user.save(function(err) {
if (err){ log.error(err) }
localStorage.setItem('username', user.vkontakteId);
localStorage.setItem('key', user.access_token)
return done(err, user);
});
} else {
vkUser = { access_token: params.access_token }
vkUser.save(function(err) {
if (err){ log.error(err) }
localStorage.setItem('key', vkUser.access_token)
return done(err, vkUser);
});
localStorage.setItem('username', vkUser.vkontakteId);
return done(err, vkUser);
}
})
Here, I check have user in my DB or not. If not: register user (and send to him his token), if have: update token (and send to him his updated token).
Why ".save is not a function"?
P.S: And how correctly send data to user localStorage?
via ALPHA
No comments:
Post a Comment