diff --git a/server/auth/google.js b/server/auth/google.js index 2fbb887ac..80bc1b16f 100644 --- a/server/auth/google.js +++ b/server/auth/google.js @@ -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) { diff --git a/server/auth/slack.js b/server/auth/slack.js index 571f09de5..9f46857f6 100644 --- a/server/auth/slack.js +++ b/server/auth/slack.js @@ -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) {