Skip to content

Commit

Permalink
Merge pull request #1393 from argos-ci/fix-account-login-error
Browse files Browse the repository at this point in the history
fix: handle update email
  • Loading branch information
gregberge authored Oct 11, 2024
2 parents 87ecedc + 702692f commit c88f4b5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions apps/backend/src/database/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,24 @@ export const getOrCreateUserAccountFromGhAccount = async (
if (existingAccount) {
invariant(existingAccount.user, "user not fetched");

const updateData: PartialModelObject<User> = {};

if (
(accessToken !== undefined &&
existingAccount.user.accessToken !== accessToken) ||
existingAccount.user.email !== email
accessToken !== undefined &&
existingAccount.user.accessToken !== accessToken
) {
await existingAccount.user.$query().patchAndFetch({
accessToken: accessToken ?? existingAccount.user.accessToken,
email,
});
updateData.accessToken = accessToken;
}

if (existingAccount.user.email !== email) {
const existingEmailUser = await User.query().findOne("email", email);
if (!existingEmailUser) {
updateData.email = email;
}
}

if (Object.keys(updateData).length > 0) {
await existingAccount.user.$query().patchAndFetch(updateData);
}

return existingAccount;
Expand Down

0 comments on commit c88f4b5

Please sign in to comment.