Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show dialog when changing email after using Google Login #9611

Conversation

JaideepGuntupalli
Copy link
Contributor

What does this PR do?

Improves the process of changing email after using Google Sign-In. Shows dialog as mentioned in #9515. Also changes ID provider from GOOGLE to CAL. Also sends a reset password mail.

Fixes #9515

https://www.loom.com/share/a99b5442c1524f0e8dfe4e43bdfe9946?sid=7c355736-03d6-4c76-b1ed-85bae506fe99

PS: I have fixed the toast issues

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)

How should this be tested?

  • Login using Google
  • Change the email
  • Reset your password using mail
  • Try to log back in

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Questions I still have?

  • Should I make a new mail to send them instead of the same forgot password mail? @PeerRich
  • Should I log out the user directly after changing the mail since it becomes a weird unauthorized error and then resulting the user to logout?

@vercel
Copy link

vercel bot commented Jun 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2023 10:29pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Aug 3, 2023 10:29pm

@vercel
Copy link

vercel bot commented Jun 18, 2023

@JaideepGuntupalli is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added Medium priority Created by Linear-GitHub Sync 🧹 Improvements Improvements to existing features. Mostly UX/UI labels Jun 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@keithwillcode keithwillcode requested a review from a team June 18, 2023 19:04
@PeerRich
Copy link
Member

oh hell yeah. this is a super common issue we have and will ease the pain for our customer support team!

@PeerRich PeerRich changed the title Improvement: When changing email after using Google Login feat: show dialog when changing email after using Google Login Jun 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 19, 2023

Thank you for following the naming conventions! 🙏

@JaideepGuntupalli
Copy link
Contributor Author

oh hell yeah. this is a super common issue we have and will ease the pain for our customer support team!

@PeerRich I have made the change, now the user will be logged out as soon as the request to change the email goes through. I have also added clear messaging on the logout screen too.

image

Copy link
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamentally this is fine; ideally this should be modified to be google agnostic - this issue also affects SAML users for example - by generalising it (given some suggestions) this can easily be achieved. Let me know what you think 👍

packages/lib/serverConfig.ts Outdated Show resolved Hide resolved
apps/web/public/static/locales/en/common.json Outdated Show resolved Hide resolved
apps/web/pages/settings/my-account/profile.tsx Outdated Show resolved Hide resolved
apps/web/pages/settings/my-account/profile.tsx Outdated Show resolved Hide resolved
@JaideepGuntupalli
Copy link
Contributor Author

JaideepGuntupalli commented Jun 21, 2023

Fundamentally this is fine; ideally this should be modified to be google agnostic - this issue also affects SAML users for example - by generalising it (given some suggestions) this can easily be achieved. Let me know what you think 👍

So shall I make it generalized so that not only people who log in with Google, every other user who makes their account using different methods than CAL will need to go through this process? @emrysal Shall I hold off on changes related to generalization till others give in their input?

Another concern I have with this approach is, disconnecting accounts from SAML will not cause any issues right?
PS: I have been going through the codebase for only the past 10 days so I have no clue how Teams and SAML logins work.

Copy link
Contributor

@Udit-takkar Udit-takkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I still get unauthorised in this PR when i change email and reset password email is sent and then i am redirected to logout screen. I fixed this unauthorised bug here fix: email update bug #10306. you would resolve the conflicts and update the branch and we should only signout when changed other provider(like gmail) to CAL.

  2. I know you removed the identity provider id in update profile but if i try to login with gmail ( the provider) after changing my provider to CAL. I am still able to login for some reason and the DB removes the password field and sets identity provider id.

  3. E2E tests are failing

Left few more comments in the code

@PeerRich
Copy link
Member

/bonus 10 @JaideepGuntupalli would you mind addressing the comments by @Udit-takkar and fix the small merge conflict?

@JaideepGuntupalli
Copy link
Contributor Author

sure currently outside but will do by tomorrow. this week i hv been busy.

@algora-pbc
Copy link

algora-pbc bot commented Jul 28, 2023

A bonus of $10 has been added by PeerRich.
@JaideepGuntupalli: You will receive $10 once you implement the requested changes and your PR is merged.

@JaideepGuntupalli
Copy link
Contributor Author

Hey @PeerRich @Udit-takkar, sorry for the delay. I am actually busy moving back to college. I will try to get this done as soon as I can.

# Conflicts:
#	apps/web/pages/auth/logout.tsx
#	apps/web/pages/settings/my-account/profile.tsx
@zomars
Copy link
Member

zomars commented Aug 3, 2023

Reviewing now...

@zomars
Copy link
Member

zomars commented Aug 3, 2023

Fixed conflicts. Removed delay as it's not needed. Made some type fixes.

Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution 🙏 Will block to make some adjustments

apps/web/pages/auth/logout.tsx Outdated Show resolved Hide resolved
.status(201)
.json({ message: "If this email exists in our system, you should receive a Reset email." });
// Don't leak info about whether the user exists
if (!user) return res.status(201).json({ message: "password_reset_email_sent" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to send a localized error message here. The client should handle it. Just double checked and we don't actually use this message in the frontend anyways.

@@ -40,8 +38,6 @@ export default function ForgotPassword({ csrfToken }: { csrfToken: string }) {
const json = await res.json();
if (!res.ok) {
setError(json);
} else if ("resetLink" in json) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed for forgot-password E2E test but we don't rely on this anymore

Comment on lines +32 to +36
const message = () => {
if (props.query?.passReset === "true") return "reset_your_password";
if (props.query?.emailChange === "true") return "email_change";
return "hope_to_see_you_soon";
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More legible than a ternary if you ask me. No need for constants either.

@@ -84,6 +84,7 @@
"event_awaiting_approval_recurring": "A recurring event is waiting for your approval",
"someone_requested_an_event": "Someone has requested to schedule an event on your calendar.",
"someone_requested_password_reset": "Someone has requested a link to change your password.",
"password_reset_email_sent": "If this email exists in our system, you should receive a reset email.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the original message

language: t,
user,
resetLink,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the return as we don't need it anymore

Comment on lines -59 to -67
const userToUpdate = await prisma.user.findUnique({
where: {
id: user.id,
},
});

if (!userToUpdate) {
throw new TRPCError({ code: "NOT_FOUND", message: "User not found" });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already fetch on user context. This extra query is not needed.

@@ -98,12 +94,26 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
});
}
}
const hasEmailBeenChanged = userToUpdate.email !== data.email;
const hasEmailBeenChanged = data.email && user.email !== data.email;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was true even if there was no email in data/input.

Comment on lines +103 to +115
// check if we are changing email and identity provider is not CAL
const hasEmailChangedOnNonCalProvider =
hasEmailBeenChanged && user.identityProvider !== IdentityProvider.CAL;
const hasEmailChangedOnCalProvider = hasEmailBeenChanged && user.identityProvider === IdentityProvider.CAL;

if (hasEmailChangedOnNonCalProvider) {
// Only validate if we're changing email
data.identityProvider = IdentityProvider.CAL;
data.identityProviderId = null;
} else if (hasEmailChangedOnCalProvider) {
// when the email changes, the user needs to sign in again.
signOutUser = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the behavior before updating and added again after updating.

Comment on lines +135 to +141
if (hasEmailChangedOnNonCalProvider) {
// Because the email has changed, we are now attempting to use the CAL provider-
// which has no password yet. We have to send the reset password email.
await passwordResetRequest(updatedUser);
signOutUser = true;
passwordReset = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we handle after updating.

Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it's working locally. Thank you for your contribution 🙏

@zomars zomars merged commit 123ecf3 into calcom:main Aug 4, 2023
28 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authentication area: authentication, auth, google sign in, password, SAML, password reset, can't log in High priority Created by Linear-GitHub Sync 🧹 Improvements Improvements to existing features. Mostly UX/UI
Projects
None yet
7 participants