Skip to content

Commit

Permalink
fix: handle update email
Browse files Browse the repository at this point in the history
Fix ARGOS-SERVER-XQ5
  • Loading branch information
gregberge committed Oct 11, 2024
1 parent 87ecedc commit 702692f
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 702692f

Please sign in to comment.