[GH-ISSUE #991] BUG: authClient.deleteUser does not work - it sends request without token #8539

Closed
opened 2026-04-13 03:38:40 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @JosipPardon on GitHub (Dec 22, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/991

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

function UserDeletion() {
  const [userTokenInput, setUserTokenInput] = useState("");
  const [tokenWasSent, setTokenWasSent] = useState(false);

  if (!tokenWasSent) {
    return (
      <button
        onClick={async () => {
          const result = await authClient.deleteUser(); // this triggers execution of sendDeleteAccountVerification in auth.ts
          setTokenWasSent(true);
          console.log("#1", result);
        }}
      >
        Send token
      </button>
    );
  } else {
    return (
      <>
        <input
          placeholder="Enter token"
          value={userTokenInput}
          onChange={(e) => setUserTokenInput(e.target.value)}
        />
        <button
          onClick={async () => {
            const result = await authClient.deleteUser({
              token: userTokenInput,
            });
            console.log("#2", result);
          }}
        >
          Confirm token
        </button>
      </>
    );
  }
}

auth.ts (simplified):

user: {
  deleteUser: {
    enabled: true,
    sendDeleteAccountVerification: async (
      data: {
        user,
        url,
        token
      },
      request 
    ) => {
      console.log(
        `Account deletion token for ${data.user.email} is ${data.token}`
      );
    }
  },
},

Current vs. Expected behavior

Second result is problematic:
image

It seems that authClient.deleteUser sends request without token included. This can also be seen in network logs:
image

My temporary solution is this:

const result = (await (
  await fetch(
    `/api/auth/delete-user/callback?token=${userTokenInput}`
  )
).json());
window.location.reload();

I think that this is what authClient.deleteUser is supposed to do, but it is not properly configured.

What version of Better Auth are you using?

1.1.1

Provide environment information

Macbook, Safari
React 19 and Next.js 15

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

provided above

Additional context

No response

Originally created by @JosipPardon on GitHub (Dec 22, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/991 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce ```tsx function UserDeletion() { const [userTokenInput, setUserTokenInput] = useState(""); const [tokenWasSent, setTokenWasSent] = useState(false); if (!tokenWasSent) { return ( <button onClick={async () => { const result = await authClient.deleteUser(); // this triggers execution of sendDeleteAccountVerification in auth.ts setTokenWasSent(true); console.log("#1", result); }} > Send token </button> ); } else { return ( <> <input placeholder="Enter token" value={userTokenInput} onChange={(e) => setUserTokenInput(e.target.value)} /> <button onClick={async () => { const result = await authClient.deleteUser({ token: userTokenInput, }); console.log("#2", result); }} > Confirm token </button> </> ); } } ``` auth.ts (simplified): ```ts user: { deleteUser: { enabled: true, sendDeleteAccountVerification: async ( data: { user, url, token }, request ) => { console.log( `Account deletion token for ${data.user.email} is ${data.token}` ); } }, }, ``` ### Current vs. Expected behavior Second `result` is problematic: <img width="1036" alt="image" src="https://github.com/user-attachments/assets/92682105-1ed1-45f6-8ad2-89b536aa56a3" /> It seems that `authClient.deleteUser` sends request without token included. This can also be seen in network logs: <img width="1004" alt="image" src="https://github.com/user-attachments/assets/44a9305a-8812-42aa-950e-b26c14c54e7f" /> My temporary solution is this: ```js const result = (await ( await fetch( `/api/auth/delete-user/callback?token=${userTokenInput}` ) ).json()); window.location.reload(); ``` I think that this is what `authClient.deleteUser` is supposed to do, but it is not properly configured. ### What version of Better Auth are you using? 1.1.1 ### Provide environment information ```bash Macbook, Safari React 19 and Next.js 15 ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript provided above ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:38:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8539