fix: User records not written correctly on signin (#1119)
* Initial fix for #1116 * clarify logic
This commit is contained in:
@@ -89,12 +89,15 @@ router.get('google.callback', auth({ required: false }), async ctx => {
|
||||
serviceId: profile.data.id,
|
||||
},
|
||||
{
|
||||
service: '',
|
||||
service: { [Op.eq]: null },
|
||||
email: profile.data.email,
|
||||
},
|
||||
],
|
||||
teamId: team.id,
|
||||
},
|
||||
defaults: {
|
||||
service: 'google',
|
||||
serviceId: profile.data.id,
|
||||
name: profile.data.name,
|
||||
email: profile.data.email,
|
||||
isAdmin: isFirstUser,
|
||||
@@ -102,6 +105,25 @@ router.get('google.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: 'google',
|
||||
serviceId: profile.data.id,
|
||||
avatarUrl: profile.data.picture,
|
||||
});
|
||||
}
|
||||
|
||||
// update email address if it's changed in Google
|
||||
if (!isFirstSignin && profile.data.email !== user.email) {
|
||||
await user.update({ email: profile.data.email });
|
||||
}
|
||||
|
||||
if (isFirstUser) {
|
||||
await team.provisionFirstCollection(user.id);
|
||||
await team.provisionSubdomain(hostname);
|
||||
}
|
||||
|
||||
if (isFirstSignin) {
|
||||
await Event.create({
|
||||
name: 'users.create',
|
||||
@@ -116,16 +138,6 @@ router.get('google.callback', auth({ required: false }), async ctx => {
|
||||
});
|
||||
}
|
||||
|
||||
// update email address if it's changed in Google
|
||||
if (!isFirstSignin && profile.data.email !== user.email) {
|
||||
await user.update({ email: profile.data.email });
|
||||
}
|
||||
|
||||
if (isFirstUser) {
|
||||
await team.provisionFirstCollection(user.id);
|
||||
await team.provisionSubdomain(hostname);
|
||||
}
|
||||
|
||||
// set cookies on response and redirect to team subdomain
|
||||
ctx.signIn(user, team, 'google', isFirstSignin);
|
||||
} catch (err) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user