Unable to use admin plugin with convex component #2773

Closed
opened 2026-03-13 10:19:19 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @KiskaLE on GitHub (Jan 27, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When I try to use admin plugin with convex component, column role is not created in schema after npx run dev

// /convex/auth.ts
import { createClient, type GenericCtx } from "@convex-dev/better-auth";
import { convex } from "@convex-dev/better-auth/plugins";
import { components } from "./_generated/api";
import { DataModel } from "./_generated/dataModel";
import { query } from "./_generated/server";
import { betterAuth } from "better-auth";
import { createAuthMiddleware, APIError } from "better-auth/api";
import authConfig from "./auth.config";

const siteUrl = process.env.SITE_URL!;

// The component client has methods needed for integrating Convex with Better Auth,
// as well as helper methods for general use.
export const authComponent = createClient<DataModel>(components.betterAuth);

export const createAuth = (ctx: GenericCtx<DataModel>) => {
    return betterAuth({
        baseURL: siteUrl,
        database: authComponent.adapter(ctx),
        // Configure simple, non-verified email/password
        emailAndPassword: {
            enabled: true,
            requireEmailVerification: false,
        },
        hooks: {
            before: createAuthMiddleware(async (ctx) => {
                if (ctx.path === "/sign-up/email") {
                    const allowRegistration = process.env.ALLOW_REGISTRATION !== "false";
                    if (!allowRegistration) {
                        throw new APIError("BAD_REQUEST", {
                            message: "Registration is disabled",
                        });
                    }
                }
            }),
        },
        plugins: [
            // The Convex plugin is required for Convex compatibility
            convex({ authConfig }),
        ],
    });
};

// Get the current authenticated user
export const getCurrentUser = query({
    args: {},
    handler: async (ctx) => {
        return authComponent.getAuthUser(ctx);
    },
});

// /convex/auth.config.ts
import { getAuthConfigProvider } from "@convex-dev/better-auth/auth-config";
import type { AuthConfig } from "convex/server";

export default {
  providers: [getAuthConfigProvider()],
} satisfies AuthConfig;

// /convex/convex.config.ts
import { defineApp } from "convex/server";
import betterAuth from "@convex-dev/better-auth/convex.config";

const app = defineApp();
app.use(betterAuth);

export default app;

Current vs. Expected behavior

Current:
Using better-auth with convex using admin plugin doesn't create correct column in schema.

Expected:
convex creates correct schema when using admin plugin

What version of Better Auth are you using?

1.4.13

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Fri, 02 Jan 2026 17:52:55 +0000",
    "release": "6.18.3-arch1-1",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 5700",
    "totalMemory": "38.96 GB",
    "freeMemory": "31.82 GB"
  },
  "node": {
    "version": "v25.2.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "latest"
    },
    {
      "name": "react",
      "version": "^19.2.3"
    },
    {
      "name": "hono",
      "version": "^4.11.4"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.13",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { createClient, type GenericCtx } from "@convex-dev/better-auth";
import { convex } from "@convex-dev/better-auth/plugins";
import { components } from "./_generated/api";
import { DataModel } from "./_generated/dataModel";
import { query } from "./_generated/server";
import { betterAuth } from "better-auth";
import { createAuthMiddleware, APIError } from "better-auth/api";
import authConfig from "./auth.config";

const siteUrl = process.env.SITE_URL!;

// The component client has methods needed for integrating Convex with Better Auth,
// as well as helper methods for general use.
export const authComponent = createClient<DataModel>(components.betterAuth);

export const createAuth = (ctx: GenericCtx<DataModel>) => {
    return betterAuth({
        baseURL: siteUrl,
        database: authComponent.adapter(ctx),
        // Configure simple, non-verified email/password
        emailAndPassword: {
            enabled: true,
            requireEmailVerification: false,
        },
        hooks: {
            before: createAuthMiddleware(async (ctx) => {
                if (ctx.path === "/sign-up/email") {
                    const allowRegistration = process.env.ALLOW_REGISTRATION !== "false";
                    if (!allowRegistration) {
                        throw new APIError("BAD_REQUEST", {
                            message: "Registration is disabled",
                        });
                    }
                }
            }),
        },
        plugins: [
            // The Convex plugin is required for Convex compatibility
            convex({ authConfig }),
        ],
    });
};

// Get the current authenticated user
export const getCurrentUser = query({
    args: {},
    handler: async (ctx) => {
        return authComponent.getAuthUser(ctx);
    },
});

Additional context

No response

Originally created by @KiskaLE on GitHub (Jan 27, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When I try to use `admin` plugin with convex component, column role is not created in schema after `npx run dev` ``` typescript // /convex/auth.ts import { createClient, type GenericCtx } from "@convex-dev/better-auth"; import { convex } from "@convex-dev/better-auth/plugins"; import { components } from "./_generated/api"; import { DataModel } from "./_generated/dataModel"; import { query } from "./_generated/server"; import { betterAuth } from "better-auth"; import { createAuthMiddleware, APIError } from "better-auth/api"; import authConfig from "./auth.config"; const siteUrl = process.env.SITE_URL!; // The component client has methods needed for integrating Convex with Better Auth, // as well as helper methods for general use. export const authComponent = createClient<DataModel>(components.betterAuth); export const createAuth = (ctx: GenericCtx<DataModel>) => { return betterAuth({ baseURL: siteUrl, database: authComponent.adapter(ctx), // Configure simple, non-verified email/password emailAndPassword: { enabled: true, requireEmailVerification: false, }, hooks: { before: createAuthMiddleware(async (ctx) => { if (ctx.path === "/sign-up/email") { const allowRegistration = process.env.ALLOW_REGISTRATION !== "false"; if (!allowRegistration) { throw new APIError("BAD_REQUEST", { message: "Registration is disabled", }); } } }), }, plugins: [ // The Convex plugin is required for Convex compatibility convex({ authConfig }), ], }); }; // Get the current authenticated user export const getCurrentUser = query({ args: {}, handler: async (ctx) => { return authComponent.getAuthUser(ctx); }, }); ``` ``` typescript // /convex/auth.config.ts import { getAuthConfigProvider } from "@convex-dev/better-auth/auth-config"; import type { AuthConfig } from "convex/server"; export default { providers: [getAuthConfigProvider()], } satisfies AuthConfig; ``` ``` typescript // /convex/convex.config.ts import { defineApp } from "convex/server"; import betterAuth from "@convex-dev/better-auth/convex.config"; const app = defineApp(); app.use(betterAuth); export default app; ``` ### Current vs. Expected behavior Current: Using better-auth with convex using admin plugin doesn't create correct column in schema. Expected: convex creates correct schema when using admin plugin ### What version of Better Auth are you using? 1.4.13 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Fri, 02 Jan 2026 17:52:55 +0000", "release": "6.18.3-arch1-1", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 5700", "totalMemory": "38.96 GB", "freeMemory": "31.82 GB" }, "node": { "version": "v25.2.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "latest" }, { "name": "react", "version": "^19.2.3" }, { "name": "hono", "version": "^4.11.4" } ], "databases": null, "betterAuth": { "version": "^1.4.13", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { createClient, type GenericCtx } from "@convex-dev/better-auth"; import { convex } from "@convex-dev/better-auth/plugins"; import { components } from "./_generated/api"; import { DataModel } from "./_generated/dataModel"; import { query } from "./_generated/server"; import { betterAuth } from "better-auth"; import { createAuthMiddleware, APIError } from "better-auth/api"; import authConfig from "./auth.config"; const siteUrl = process.env.SITE_URL!; // The component client has methods needed for integrating Convex with Better Auth, // as well as helper methods for general use. export const authComponent = createClient<DataModel>(components.betterAuth); export const createAuth = (ctx: GenericCtx<DataModel>) => { return betterAuth({ baseURL: siteUrl, database: authComponent.adapter(ctx), // Configure simple, non-verified email/password emailAndPassword: { enabled: true, requireEmailVerification: false, }, hooks: { before: createAuthMiddleware(async (ctx) => { if (ctx.path === "/sign-up/email") { const allowRegistration = process.env.ALLOW_REGISTRATION !== "false"; if (!allowRegistration) { throw new APIError("BAD_REQUEST", { message: "Registration is disabled", }); } } }), }, plugins: [ // The Convex plugin is required for Convex compatibility convex({ authConfig }), ], }); }; // Get the current authenticated user export const getCurrentUser = query({ args: {}, handler: async (ctx) => { return authComponent.getAuthUser(ctx); }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 10:19:19 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 27, 2026):

It seems you are encountering issues where the admin plugin with the Convex component does not create the expected column role in your schema when using Better Auth version 1.4.13. This could be related to how the admin plugin is integrated and the necessary migrations may not have been executed.

To resolve this, try the following steps:

  1. Migration: Ensure that you have run the necessary migrations to update your database schema. This includes running:

    npx @better-auth/cli migrate
    

    This command should create all necessary fields, including roles, in the schema.

  2. Schema Generation: You may also want to regenerate the schema with:

    npx @better-auth/cli generate
    
  3. Configuration Alignment: Verify that your auth.ts and auth.config.ts files correctly include the admin plugin and its configuration as specified in the documentation. Ensure that the admin plugin is explicitly added and properly configured.

  4. Check Version Compatibility: Make sure that the versions of Better Auth and the Convex package are compatible and reflect the actual capabilities, as outlined in the documentation.

If these steps do not resolve your issue, consider checking the GitHub repository for related issues or posting your specific case there. There is an open discussion regarding how roles should be handled with the admin plugin, which might give you further insights into your problem [1], [2], [3].

If you've tried the above and need more assistance, feel free to tag @bekacru or @ping__ for direct support from the Better Auth team. What specific error are you seeing during migration, or have you managed to run the commands successfully?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 27, 2026): It seems you are encountering issues where the `admin` plugin with the Convex component does not create the expected column role in your schema when using Better Auth version 1.4.13. This could be related to how the admin plugin is integrated and the necessary migrations may not have been executed. To resolve this, try the following steps: 1. **Migration**: Ensure that you have run the necessary migrations to update your database schema. This includes running: ```bash npx @better-auth/cli migrate ``` This command should create all necessary fields, including roles, in the schema. 2. **Schema Generation**: You may also want to regenerate the schema with: ```bash npx @better-auth/cli generate ``` 3. **Configuration Alignment**: Verify that your `auth.ts` and `auth.config.ts` files correctly include the admin plugin and its configuration as specified in the documentation. Ensure that the admin plugin is explicitly added and properly configured. 4. **Check Version Compatibility**: Make sure that the versions of Better Auth and the Convex package are compatible and reflect the actual capabilities, as outlined in the documentation. If these steps do not resolve your issue, consider checking the GitHub repository for related issues or posting your specific case there. There is an open discussion regarding how roles should be handled with the admin plugin, which might give you further insights into your problem [[1]](https://github.com/better-auth/better-auth/pull/7522), [[2]](https://github.com/better-auth/better-auth/pull/6626), [[3]](https://www.better-auth.com/docs/plugins/admin). If you've tried the above and need more assistance, feel free to tag @bekacru or @ping__ for direct support from the Better Auth team. What specific error are you seeing during migration, or have you managed to run the commands successfully? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 27, 2026):

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

This is a known limitation: the admin plugin in Better Auth does not automatically add the required fields (like role, banned, banReason, banExpires) to your Convex schema. The CLI generate/migrate commands only add these fields automatically for the built-in Kysely adapter, not for Convex or Drizzle. You need to manually add the following fields to your user schema after running any generate or migration commands:

  • role (string, optional, default: "user")
  • banned (boolean, optional, default: false)
  • banReason (string, optional)
  • banExpires (date, optional)

If these fields are missing, user creation or login can silently fail or throw errors, since the admin plugin expects them to exist. There is no config or CLI workaround for this as of v1.4.13—manual schema editing is required. This is documented in the admin plugin docs and discussed in several issues (example, example, docs).

After updating your Convex schema to include these fields, the admin plugin should work as expected. Keep an eye on future releases in case this limitation is addressed.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 27, 2026): <!-- Greeting --> Hi @KiskaLE! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known limitation: the admin plugin in Better Auth does not automatically add the required fields (like role, banned, banReason, banExpires) to your Convex schema. The CLI generate/migrate commands only add these fields automatically for the built-in Kysely adapter, not for Convex or Drizzle. You need to manually add the following fields to your user schema after running any generate or migration commands: - role (string, optional, default: "user") - banned (boolean, optional, default: false) - banReason (string, optional) - banExpires (date, optional) If these fields are missing, user creation or login can silently fail or throw errors, since the admin plugin expects them to exist. There is no config or CLI workaround for this as of v1.4.13—manual schema editing is required. This is documented in the admin plugin docs and discussed in several issues ([example](https://github.com/better-auth/better-auth/issues/7611), [example](https://github.com/better-auth/better-auth/issues/4795), [docs](https://github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/docs/content/docs/plugins/admin.mdx#L11-L742)). After updating your Convex schema to include these fields, the admin plugin should work as expected. Keep an eye on future releases in case this limitation is addressed. <!-- 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/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/a5fc52b3-6f77-4a57-bf27-1e83950fc823?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20limitation%3A%20the%20admin%20plugin%20in%20Better%20Auth%20does%20not%20automatically%20add%20the%20required%20fields%20%28like%20role%2C%20banned%2C%20banReason%2C%20banExpires%29%20to%20your%20Convex%20schema.%20The%20CLI%20generate/migrate%20commands%20only%20add%20these%20fields%20automatically%20for%20the%20built-in%20Kysely%20adapter%2C%20not%20for%20Convex%20or%20Drizzle.%20You%20need%20to%20manually%20add%20the%20following%20fields%20to%20your%20user%20schema%20after%20running%20any%20generate%20or%20migration%20commands%3A%0A%0A-%20role%20%28string%2C%20optional%2C%20default%3A%20%22user%22%29%0A-%20banned%20%28boolean%2C%20optional%2C%20default%3A%20false%29%0A-%20banReason%20%28string%2C%20optional%29%0A-%20banExpires%20%28date%2C%20optional%29%0A%0AIf%20these%20fields%20are%20missing%2C%20user%20creation%20or%20login%20can%20silently%20fail%20or%20throw%20errors%2C%20since%20the%20admin%20plugin%20expects%20them%20to%20exist.%20There%20is%20no%20config%20or%20CLI%20workaround%20for%20this%20as%20of%20v1.4.13%E2%80%94manual%20schema%20editing%20is%20required.%20This%20is%20documented%20in%20the%20admin%20plugin%20docs%20and%20discussed%20in%20several%20issues%20%28%5Bexample%5D%28https%3A//github.com/better-auth/better-auth/issues/7611%29%2C%20%5Bexample%5D%28https%3A//github.com/better-auth/better-auth/issues/4795%29%2C%20%5Bdocs%5D%28https%3A//github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/docs/content/docs/plugins/admin.mdx%23L11-L742%29%29.%0A%0AAfter%20updating%20your%20Convex%20schema%20to%20include%20these%20fields%2C%20the%20admin%20plugin%20should%20work%20as%20expected.%20Keep%20an%20eye%20on%20future%20releases%20in%20case%20this%20limitation%20is%20addressed.)&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/7635)
Author
Owner

@bytaesu commented on GitHub (Jan 27, 2026):

Hi @KiskaLE,

Convex components can be installed through NPM or local folder. The NPM version you're currently using does not support the Admin plugin. We've updated the Convex integration guide. It’s available on canary now and will be deployed soon. Please refer to the links below to use the Admin plugin.

If you have further questions, feel free to mention me 🙂

@bytaesu commented on GitHub (Jan 27, 2026): Hi @KiskaLE, Convex components can be installed through NPM or local folder. The NPM version you're currently using does not support the Admin plugin. We've updated the Convex integration guide. It’s available on canary now and will be deployed soon. Please refer to the links below to use the Admin plugin. - https://canary.better-auth.com/docs/integrations/convex - https://labs.convex.dev/better-auth/features/local-install If you have further questions, feel free to mention me 🙂
Author
Owner

@Rolanddoda commented on GitHub (Jan 28, 2026):

@bytaesu are you sure there is a mention about Admin Plugin in these links? I didn't find anything related to the Admin Plugin in there

@Rolanddoda commented on GitHub (Jan 28, 2026): @bytaesu are you sure there is a mention about Admin Plugin in these links? I didn't find anything related to the Admin Plugin in there
Author
Owner

@bytaesu commented on GitHub (Jan 28, 2026):

@bytaesu are you sure there is a mention about Admin Plugin in these links? I didn't find anything related to the Admin Plugin in there

With this approach, all plugins can be used 🙂

@bytaesu commented on GitHub (Jan 28, 2026): > @bytaesu are you sure there is a mention about Admin Plugin in these links? I didn't find anything related to the Admin Plugin in there With this approach, all plugins can be used 🙂
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2773