Skip to content
Alchemy Logo

useSetEmail

function useSetEmail(mutationArgs?): UseSetEmailResult;

Defined in: account-kit/react/src/hooks/useSetEmail.ts:76

A custom hook to set an email address for an already authenticated account.

Note: You should first use the useSendVerificationCode hook to send a verification code to the email address before calling this hook.

import { useSetEmail, useSendVerificationCode } from "@account-kit/react";
 
// First, send verification code
const { sendVerificationCode } = useSendVerificationCode();
 
const { setEmail, isSettingEmail, error } = useSetEmail({
  onSuccess: () => {
    // do something when email is successfully set
  },
  onError: (error) => console.error(error),
});
 
// Step 1: Send verification code to email
await sendVerificationCode({
  type: "email",
  contact: "[email protected]",
});
 
// Step 2: Update email using verification code
setEmail({
  verificationCode: "123456", // code user received
});
 
// DEPRECATED: Use with just email string (for backward compatibility)
setEmail("[email protected]");

ParameterTypeDescription

mutationArgs?

Partial<Omit<UseMutationOptions<void, Error, SetEmailParams, unknown>, "mutationFn" | "mutationKey">>

Optional arguments for the setEmail mutation

UseSetEmailResult

An object containing functions and state for setting the email

Was this page helpful?