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

Passwordless | Add countdown timer to "send again" functionality #3045

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

coldlink
Copy link
Member

@coldlink coldlink commented Jan 27, 2025

What does this change?

A number of users are complaining that they're getting multiple passcodes to their email, each time with a different code, and the original code no longer valid.

We think this is due to delays in the user receiving the email

So rather than allow the user to resend the passcode straight away, we added a countdown timer so that they can only do it after a specificed amount of time, currently set to 30 seconds.

We've only enabled this for passcode users, as the same problem doesn't occur with links.

We also update the MainForm component to take a disabled value.

A new hook provides the countdown functionality on the client side: useCountdownTimer
This hook takes a durationInSeconds parameter to start the countdown, and returns the timeRemaining in seconds, and an isComplete boolean.

This is then integrated withing the EmailSentInformationBox component, which houses the "send again" functionality. Where it takes a new sendAgainTimerInSeconds prop in order to control it.

In turn the same thing was applied to PasscodeEmailSent component which uses the EmailSentInformationBox, followed by the pages that use the PasscodeEmailSent component.

Finally in order to set the timer, rather than harcode the value everywhere, we add it to the ClientState and PageData objects. This allows us to only set it in one place (through getRequestState), but also lets us modify the value specifically for tests, i.e Cypress. A getPasscodeSendAgainTimer helper function helps with this.

Video
Screen.Recording.2025-01-27.at.13.04.40.mov

Tested

  • DEV
  • CODE

@coldlink coldlink added the passwordless PRs/Issues related to passwordless/passcode functionality label Jan 27, 2025
@coldlink coldlink marked this pull request as ready for review January 27, 2025 12:58
@coldlink coldlink requested a review from a team as a code owner January 27, 2025 12:58
// if we're running in cypress, we want to use the cypress mock state cookie to set the timer for testing
const runningInCypress = process.env.RUNNING_IN_CYPRESS === 'true';
if (runningInCypress) {
const cypressMockStateCookie = req.cookies['cypress-mock-state'];
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe a silly question because I don't know cypress that well:

is there any reason for this to be called cypress-mock-state and not something that refers to the timer ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because it's a pattern we use already in Gateway to customise behaviour on the sever based on Cypress tests.

So we set a cypress-mock-state cookie in other tests that also modifies behaviour is other ways only when it exists. Which is useful for testing edge case scenarios.

@coldlink coldlink merged commit f15302f into main Jan 27, 2025
21 checks passed
@coldlink coldlink deleted the mm/passcode-timer branch January 27, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
passwordless PRs/Issues related to passwordless/passcode functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants