fix: User records not written correctly on signin (#1119)

* Initial fix for #1116

* clarify logic
This commit is contained in:
Tom Moor
2019-12-22 20:14:06 -08:00
committed by GitHub
parent c20282de06
commit 98dda567c2
2 changed files with 41 additions and 17 deletions

View File

@@ -68,12 +68,15 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
serviceId: data.user.id,
},
{
service: '',
service: { [Op.eq]: null },
email: data.user.email,
},
],
teamId: team.id,
},
defaults: {
service: 'slack',
serviceId: data.user.id,
name: data.user.name,
email: data.user.email,
isAdmin: isFirstUser,
@@ -81,6 +84,20 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
},
});
// update the user with fresh details if they just accepted an invite
if (!user.serviceId || !user.service) {
await user.update({
service: 'slack',
serviceId: data.user.id,
avatarUrl: data.user.image_192,
});
}
// update email address if it's changed in Slack
if (!isFirstSignin && data.user.email !== user.email) {
await user.update({ email: data.user.email });
}
if (isFirstUser) {
await team.provisionFirstCollection(user.id);
await team.provisionSubdomain(data.team.domain);
@@ -100,11 +117,6 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
});
}
// update email address if it's changed in Slack
if (!isFirstSignin && data.user.email !== user.email) {
await user.update({ email: data.user.email });
}
// set cookies on response and redirect to team subdomain
ctx.signIn(user, team, 'slack', isFirstSignin);
} catch (err) {