Skip to content

signIn.prepareFirstFactor sending two emails with different codes #887

Description

@sgrund14

Package + Version

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • gatsby-plugin-clerk
  • build/tooling/chore
  • other:

Version:

clerk/clerk-js @ 4.27.2

Browser/OS

If applicable e.g. Chrome latest

Description

I'm trying to write a custom email_code flow like so

 const { signIn } = useSignIn();
const onEmailSubmit = useCallback(async () => {
    try {
        const signInObj = await signIn?.create({
            identifier: email,
            strategy: 'email_code',
        });
        const firstFactorObj = signInObj?.supportedFirstFactors?.find?.(
            (factor) => factor.strategy === 'email_code'
        ) as EmailCodeFactor;
        await signIn?.prepareFirstFactor({
            strategy: 'email_code',
            emailAddressId: firstFactorObj.emailAddressId || '',
        });
        console.log('email send');
        setShowTokenInput(true);
    } catch (e) {
        setHasEmailError(true);
    }
}, [email, signIn]);

And it's sending two emails instead of one. The first email has an invalid code, and the second email has a code that works. I checked to make sure that the function was only running once ("email send" only logs once), upon submitting an email address. Thus, it shouldn't be sending two emails.

Am I doing something wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions