stormblessedS
Convex Community12mo ago
12 replies
stormblessed

[Convex Auth] Clerk Integration with Convex

Clerk will automatically create a convex user for social sign ups but the same flow doesn't work for email sign ups. Convex user is not being created automatically for Email sign up flow while it works correctly for social signup and sign in.

The following is the code for email password registration.
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const [pendingVerification, setPendingVerification] = useState(false);
  const [code, setCode] = useState("");
  const [isLoading, setIsLoading] = useState(false);

  const { isLoaded, signUp, setActive } = useSignUp();

  const handleSignUp = async () => {
    if (!isLoaded) return;
    setIsLoading(true);

    try {
      await signUp.create({
        emailAddress: email,
        password,
      });

      await signUp.prepareEmailAddressVerification({ strategy: "email_code" });
      setPendingVerification(true);
    } catch (err: any) {
      Alert.alert(
        "Sign Up Error",
        err.errors?.[0]?.message || "An error occurred while signing up",
        [{ text: "OK", style: "default" }]
      );
    } finally {
      setIsLoading(false);
    }
  };

  const handleVerification = async () => {
    if (!isLoaded) return;
    setIsLoading(true);

    try {
      const completeSignUp = await signUp.attemptEmailAddressVerification({
        code,
      });

      await setActive({ session: completeSignUp.createdSessionId });

      // The _layout.tsx will handle the redirection
    } catch (err: any) {
      Alert.alert(
        "Verification Error",
        err.errors?.[0]?.message || "An error occurred during verification",
        [{ text: "OK", style: "default" }]
      );
    } finally {
      setIsLoading(false);
    }
  };
Was this page helpful?