BETTER-AUTH. UI
Mutations

useChangeEmailOtp

Confirm an email change with a code.

The address on the session changes, so the session query is refetched on success.

Usage

import type { EmailOtpAuthClient } from "@better-auth-ui/core/plugins/email-otp"
import { useAuth } from "@better-auth-ui/react"
import { useChangeEmailOtp } from "@better-auth-ui/react/plugins/email-otp"

const { authClient } = useAuth()
const { mutate: changeEmailOtp } = useChangeEmailOtp(
  authClient as EmailOtpAuthClient
)

changeEmailOtp({
  newEmail: "[email protected]",
  otp: "123456"
})

useChangeEmailOtp requires the Better Auth emailOTP plugin. Cast authClient to EmailOtpAuthClient so TypeScript picks up the plugin-extended method signature.

Options factory

import { changeEmailOtpOptions } from "@better-auth-ui/core/plugins/email-otp"
import { useMutation } from "@tanstack/react-query"

const { mutate } = useMutation(changeEmailOtpOptions(authClient))

Params

Prop

Type

Last updated on

On this page