Skip to content

fix(settings): Get email from account hook instead of location state#18157

Merged
jonalmeida merged 1 commit intomainfrom
FXA-10876
Jan 14, 2025
Merged

fix(settings): Get email from account hook instead of location state#18157
jonalmeida merged 1 commit intomainfrom
FXA-10876

Conversation

@jonalmeida
Copy link
Copy Markdown
Contributor

@jonalmeida jonalmeida commented Dec 18, 2024

⚠️ I'm not really sure, what the right behaviour should be if the email is null.

Because

  • We want to handle the missing email case and not get this information from the location state.

This pull request

  • Switches to using currentAccount.

Issue that this pull request solves

Closes: FXA-10876

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

n/a

Other information (Optional)

Built on top of #18136. Will rebase when the prior PR lands.

const account = useAccount();
const { uid, sessionToken } = currentAccount() || {};
// TODO: how do we properly handle the real non-null nature?
const { uid, sessionToken, email = '💩' } = currentAccount() || {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💩 🤣

currentAccount pulls from local storage right, which is what we want most of the time 👍 but just from a quick search, I only see us call storeAccountData in CompleteResetPassword so is this available from local storage at this point in the flow...? If not, then location state seems like maybe the correct place?

To hopefully answer the code comment question, before the return (<ResetPasswordWithRecoveryKeyVerified can we just check that these values are non-null and if so, redirect? See how we check for !email in the signin container component. (I don't think this is applicable here but if we ever have a case where we're passing non-null values into a component just to pass them back to a callback, we can curry them, see InlineRecoveryKeySetup and SetPassword containers)

FWIW related to your PR title, we shouldn't be using useAccount unless we want the entire GQL query to run, we've got a ticket to remove it in reset PW.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This page is reached after CompleteResetPassword so email should be stored in local storage at this stage - if it isn't, that means the user isn't signed in and should likely be redirected to /signin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah thanks Valerie, I can never keep these reset PW flows straight. So yeah, currentAccount is the right thing here and I think if the value is null we can just redirect to /signin as you said.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the discussion! I've updated the PR and had to rebase it on #18156 for now.

FWIW related to your PR title, we shouldn't be using useAccount unless we want the entire GQL query to run, we've got a ticket to remove it in reset PW.

Sorry, that was a typo - I meant currentAccount. This seems to be the right one that also accounts for the email that comes from a web channel message.

@jonalmeida jonalmeida force-pushed the FXA-10876 branch 2 times, most recently from f8ba615 to 5ce908e Compare January 9, 2025 19:11
@jonalmeida jonalmeida marked this pull request as ready for review January 9, 2025 19:31
@jonalmeida jonalmeida requested a review from a team as a code owner January 9, 2025 19:31
Copy link
Copy Markdown
Contributor

@vpomerleau vpomerleau left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@jonalmeida jonalmeida merged commit a929a2d into main Jan 14, 2025
@jonalmeida jonalmeida deleted the FXA-10876 branch January 14, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants