callbackOnVerification not called when updatePhoneNumber option is enabled #2001

Closed
opened 2026-03-13 09:20:12 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @kareemmahlees on GitHub (Sep 23, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure the phoneNumber plugin with a sendOtp callback and most importantly callbackOnVerification.
  2. Send an otp ( doesn't matter client-side or server-side )
  3. Now verify the top with the updatePhoneNumber option enabled.

Current vs. Expected behavior

Current

callbackOnVerficiation is not called when the updatePhoneNumber option is enabled.

Expected

the callback to be called regardless of the option

What version of Better Auth are you using?

1.3.9

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home Single Language",
    "release": "10.0.26100",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600H with Radeon Graphics         ",
    "totalMemory": "15.86 GB",
    "freeMemory": "1.81 GB"
  },
  "node": {
    "version": "v20.9.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.1.0"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "15.5.2"
    },
    {
      "name": "react",
      "version": "19.1.1"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.12.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.9",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

const options = {
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
  emailAndPassword: {
    enabled: true,
  },
  user: {
    additionalFields: {
      phone: {
        type: "string",
        required: true,
      },
      phoneNumberVerifiedAt: {
        type: "date",
        required: false,
      },
    },
  },
  plugins: [
    phoneNumber({
      schema: {
        user: {
          fields: {
            phoneNumber: "phone",
          },
        },
      },
      expiresIn: 60,
      sendOTP: async ({ code, phoneNumber }) => {...},
      callbackOnVerification: async ({ user }) => {
        console.log("called")
      },
    }),
  ],
} satisfies BetterAuthOptions;

Additional context

Looking at the below code:
987aded863/packages/better-auth/src/plugins/phone-number/index.ts (L603)
you can see that in this if statement that a return statement is done without calling the callback.
I am open to creating a PR to fix this!

Originally created by @kareemmahlees on GitHub (Sep 23, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure the `phoneNumber` plugin with a `sendOtp` callback and most importantly `callbackOnVerification`. 2. Send an otp ( doesn't matter client-side or server-side ) 3. Now verify the top with the `updatePhoneNumber` option enabled. ### Current vs. Expected behavior ### Current `callbackOnVerficiation` is not called when the `updatePhoneNumber` option is enabled. ### Expected the callback to be called regardless of the option ### What version of Better Auth are you using? 1.3.9 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home Single Language", "release": "10.0.26100", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600H with Radeon Graphics ", "totalMemory": "15.86 GB", "freeMemory": "1.81 GB" }, "node": { "version": "v20.9.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.1.0" }, "frameworks": [ { "name": "next", "version": "15.5.2" }, { "name": "react", "version": "19.1.1" } ], "databases": [ { "name": "@prisma/client", "version": "^6.12.0" } ], "betterAuth": { "version": "^1.3.9", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript const options = { database: prismaAdapter(db, { provider: "postgresql", }), emailAndPassword: { enabled: true, }, user: { additionalFields: { phone: { type: "string", required: true, }, phoneNumberVerifiedAt: { type: "date", required: false, }, }, }, plugins: [ phoneNumber({ schema: { user: { fields: { phoneNumber: "phone", }, }, }, expiresIn: 60, sendOTP: async ({ code, phoneNumber }) => {...}, callbackOnVerification: async ({ user }) => { console.log("called") }, }), ], } satisfies BetterAuthOptions; ``` ### Additional context Looking at the below code: https://github.com/better-auth/better-auth/blob/987aded86312cabf669821c4d429055799e559d1/packages/better-auth/src/plugins/phone-number/index.ts#L603 you can see that in this if statement that a return statement is done without calling the callback. I am open to creating a PR to fix this!
GiteaMirror added the bug label 2026-03-13 09:20:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 23, 2025):

Hi @kareemmahlees! I'm Dosu and I’m helping the better-auth team.

You are correct—when updatePhoneNumber is enabled, the code updates the user's phone number and verification status, then returns a response without calling callbackOnVerification. This is not documented as intentional and appears to be an oversight in the control flow. To ensure your callback is always called, you can patch the code by invoking callbackOnVerification after updating the user and before returning the JSON response in the updatePhoneNumber branch. This will align the behavior with your expectations and the rest of the plugin logic.
You can see the relevant code and the missing callback call here.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 23, 2025): <!-- Greeting --> Hi @kareemmahlees! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You are correct—when `updatePhoneNumber` is enabled, the code updates the user's phone number and verification status, then returns a response without calling `callbackOnVerification`. This is not documented as intentional and appears to be an oversight in the control flow. To ensure your callback is always called, you can patch the code by invoking `callbackOnVerification` after updating the user and before returning the JSON response in the `updatePhoneNumber` branch. This will align the behavior with your expectations and the rest of the plugin logic. You can see the relevant code and the missing callback call [here](https://github.com/better-auth/better-auth/blob/1baaccbf52803d27046dce3da57c5c7201a020fb/packages/better-auth/src/plugins/phone-number/index.ts). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/cc14ef5e-41d0-4e21-8a66-f4bbb9cc1343?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4839)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2001