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

fix(clerk-js): Avoid triggering email code verification twice on React strict mode #5095

Conversation

LauraBeatris
Copy link
Member

@LauraBeatris LauraBeatris commented Feb 6, 2025

Description

Before

CleanShot.2025-02-06.at.15.28.13.mp4

After

CleanShot.2025-02-06.at.15.29.02.mp4

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@LauraBeatris LauraBeatris self-assigned this Feb 6, 2025
Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: c35b8ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 6, 2025

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

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 7, 2025 2:25pm

@LauraBeatris LauraBeatris force-pushed the laura/sdk-1964-email-for-sign-in-with-email_code-gets-triggered-twice-when branch from 663b1d4 to 7d33778 Compare February 6, 2025 18:30
@LauraBeatris LauraBeatris marked this pull request as ready for review February 6, 2025 18:30
@LauraBeatris LauraBeatris requested a review from a team February 6, 2025 18:30
@LauraBeatris LauraBeatris force-pushed the laura/sdk-1964-email-for-sign-in-with-email_code-gets-triggered-twice-when branch from 7d33778 to 1bad83b Compare February 6, 2025 18:31
Comment on lines 65 to 68
{
name: 'prepare',
strategy: props.factor.strategy,
},
Copy link
Member

Choose a reason for hiding this comment

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

  1. Let's use a more specific name for the cache key
  2. If you go back to start and use a different identifier (email) it would not auto-prepare on render.
Suggested change
{
name: 'prepare',
strategy: props.factor.strategy,
},
{
name: 'signIn.prepareFirstFactor',
factor: props.factor,
},

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated it here: 2c03905

The behavior now is the following: It'll cache for a given identifier, so if you go back to /sign-in and submit again, it won't send another email cause it's cached - I've added a smaller stale time for that reason, unless you click to "Resend"

When refreshing the page, it'll only fetch once instead of twice (previous bug)

@LauraBeatris LauraBeatris force-pushed the laura/sdk-1964-email-for-sign-in-with-email_code-gets-triggered-twice-when branch from 2c03905 to 4c9858e Compare February 7, 2025 13:52
@LauraBeatris LauraBeatris merged commit 51af43d into main Feb 7, 2025
29 checks passed
@LauraBeatris LauraBeatris deleted the laura/sdk-1964-email-for-sign-in-with-email_code-gets-triggered-twice-when branch February 7, 2025 14:38
wobsoriano pushed a commit that referenced this pull request Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants