mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
Update to make user profile auto update on authentication
This commit is contained in:
parent
bbc7e26e77
commit
40967ce7e2
1 changed files with 24 additions and 9 deletions
33
lib/auth.js
33
lib/auth.js
|
@ -14,29 +14,44 @@ var models = require("./models");
|
|||
|
||||
function callback(accessToken, refreshToken, profile, done) {
|
||||
//logger.info(profile.displayName || profile.username);
|
||||
var stringifiedProfile = JSON.stringify(profile);
|
||||
models.User.findOrCreate({
|
||||
where: {
|
||||
profileid: profile.id.toString()
|
||||
},
|
||||
defaults: {
|
||||
profile: JSON.stringify(profile),
|
||||
profile: stringifiedProfile,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
}
|
||||
}).spread(function (user, created) {
|
||||
if (user) {
|
||||
if (user.accessToken == accessToken) {
|
||||
var needSave = false;
|
||||
if (user.profile != stringifiedProfile) {
|
||||
user.profile = stringifiedProfile;
|
||||
needSave = true;
|
||||
}
|
||||
if (user.accessToken != accessToken) {
|
||||
user.accessToken = accessToken;
|
||||
needSave = true;
|
||||
|
||||
}
|
||||
if (user.refreshToken != refreshToken) {
|
||||
user.refreshToken = refreshToken;
|
||||
needSave = true;
|
||||
|
||||
}
|
||||
if (needSave) {
|
||||
user.save().then(function () {
|
||||
if (config.debug)
|
||||
logger.info('user login: ' + user.id);
|
||||
return done(null, user);
|
||||
});
|
||||
} else {
|
||||
if (config.debug)
|
||||
logger.info('user login: ' + user.id);
|
||||
return done(null, user);
|
||||
}
|
||||
user.accessToken = accessToken;
|
||||
user.refreshToken = refreshToken;
|
||||
user.save().then(function () {
|
||||
if (config.debug)
|
||||
logger.info('user login: ' + user.id);
|
||||
return done(null, user);
|
||||
})
|
||||
}
|
||||
}).catch(function (err) {
|
||||
logger.error('auth callback failed: ' + err);
|
||||
|
|
Loading…
Reference in a new issue