Skip to main content

Overview

useVerifyEmail returns a function that submits a verification token to the server. Used with mode: "code" from useSendVerificationEmail. On success, user.isVerified is updated immediately in the local Redux store.

Usage Example

import { useVerifyEmail } from "@replyke/react-js";
import { useState } from "react";

function VerifyCodeForm() {
  const verifyEmail = useVerifyEmail();
  const [code, setCode] = useState("");
  const [error, setError] = useState("");

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    setError("");
    try {
      await verifyEmail({ token: code });
      // user.isVerified is now true locally
    } catch (err: any) {
      setError(err.response?.data?.error ?? "Verification failed.");
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      {error && <p>{error}</p>}
      <input
        value={code}
        onChange={(e) => setCode(e.target.value)}
        placeholder="Enter verification code"
      />
      <button type="submit">Verify</button>
    </form>
  );
}

Parameters

The returned function accepts:
token
string
required
The verification token entered by the user. Must match the token from the most recent verification email exactly.

Returns

The hook returns an async function. That function resolves to:
success
boolean
true when verification succeeded.
On success, user.isVerified is optimistically set to true in the local Redux store immediately — no need to refetch the user.

See Also