Cole
Cole4w ago

@erquhart any idea how I can use

@erquhart any idea how I can use setUserPassword from better-auth admin?
16 Replies
erquhart
erquhart4w ago
looking at this Are you sure you added the admin plugin to your createAuth?
Cole
ColeOP4w ago
@erquhart yessir I am able to use it, but the types don't seem to be implemented
erquhart
erquhart4w ago
I'm running one of the examples with the admin plugin and the types are inferred correctly, eg., setUserPassword is there
No description
Cole
ColeOP4w ago
What's wrong with mine then lol @erquhart
No description
erquhart
erquhart4w ago
Hard to say, can you share the top of the file with imports and your file that defines createAuth?
Cole
ColeOP4w ago
// Imports
import { v } from "convex/values";
import { mutation, query } from "./_generated/server";
import { Id } from "./_generated/dataModel";
import { internal } from "./_generated/api";
import { createAuth } from "../lib/auth";
import { betterAuthComponent } from "./auth";

// auth.ts
import { convexAdapter } from "@convex-dev/better-auth";
import { convex } from "@convex-dev/better-auth/plugins";
import { betterAuth } from "better-auth";
import { admin as adminPlugin } from "better-auth/plugins";

import { betterAuthComponent } from "../convex/auth";
import { type GenericCtx } from "../convex/_generated/server";

// You'll want to replace this with an environment variable
const siteUrl = process.env.NODE_ENV === "production"
? "http://192.168.1.165:3000"
: "http://localhost:3000";

export const createAuth: (ctx: GenericCtx) => ReturnType<typeof betterAuth> = (ctx: GenericCtx) =>
// Configure your Better Auth instance here
betterAuth({
// All auth requests will be proxied through your next.js server
baseURL: siteUrl,
database: convexAdapter(ctx, betterAuthComponent),
trustedOrigins: [siteUrl, "http://localhost:3000", "http://192.168.1.165:3000"],

// Simple non-verified email/password to get started
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
},

rateLimit: {
enabled: false,
},

plugins: [
// The Convex plugin is required
convex(),
adminPlugin(),
],
});
// Imports
import { v } from "convex/values";
import { mutation, query } from "./_generated/server";
import { Id } from "./_generated/dataModel";
import { internal } from "./_generated/api";
import { createAuth } from "../lib/auth";
import { betterAuthComponent } from "./auth";

// auth.ts
import { convexAdapter } from "@convex-dev/better-auth";
import { convex } from "@convex-dev/better-auth/plugins";
import { betterAuth } from "better-auth";
import { admin as adminPlugin } from "better-auth/plugins";

import { betterAuthComponent } from "../convex/auth";
import { type GenericCtx } from "../convex/_generated/server";

// You'll want to replace this with an environment variable
const siteUrl = process.env.NODE_ENV === "production"
? "http://192.168.1.165:3000"
: "http://localhost:3000";

export const createAuth: (ctx: GenericCtx) => ReturnType<typeof betterAuth> = (ctx: GenericCtx) =>
// Configure your Better Auth instance here
betterAuth({
// All auth requests will be proxied through your next.js server
baseURL: siteUrl,
database: convexAdapter(ctx, betterAuthComponent),
trustedOrigins: [siteUrl, "http://localhost:3000", "http://192.168.1.165:3000"],

// Simple non-verified email/password to get started
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
},

rateLimit: {
enabled: false,
},

plugins: [
// The Convex plugin is required
convex(),
adminPlugin(),
],
});
erquhart
erquhart4w ago
Your return type is wiping out type inference
Cole
ColeOP4w ago
that'll do it If i don't have that typescript freaks out at me
erquhart
erquhart4w ago
What error(s) are you seeing
Cole
ColeOP4w ago
The inferred type of 'createAuth' cannot be named without a reference to '.pnpm/zod@3.25.76/node_modules/zod'. This is likely not portable. A type annotation is necessary.ts(2742) Ctrl+click to open in new tab The inferred type of 'createAuth' cannot be named without a reference to '.pnpm/zod@4.0.14/node_modules/zod/v4/core'. This is likely not portable. A type annotation is necessary.ts(2742) Ctrl+click to open in new tab Exported variable 'createAuth' has or is using name 'SessionWithImpersonatedBy' from external module "/home/cole/Documents/mantis-os/node_modules/.pnpm/better-auth@1.3.3_react-dom@19.1.1_react@19.1.1react@19.1.1/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023) Ctrl+click to open in new tab Exported variable 'createAuth' has or is using name 'UserWithRole' from external module "/home/cole/Documents/mantis-os/node_modules/.pnpm/better-auth@1.3.3_react-dom@19.1.1_react@19.1.1react@19.1.1/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023) Ctrl+click to open in new tab The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.ts(7056)
erquhart
erquhart4w ago
pnpm is not happy
Cole
ColeOP4w ago
I probably have something seriously wrong with my typescript config / monorepo setup
erquhart
erquhart4w ago
maybe try deleting lockfile and node modules and reinstalling
Cole
ColeOP4w ago
will give that a shot no luck...
Exported variable 'createAuth' has or is using name 'SessionWithImpersonatedBy' from external module "/home/cole/Documents/mantis-os/packages/backend/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023)
Ctrl+click to open in new tab
Exported variable 'createAuth' has or is using name 'UserWithRole' from external module "/home/cole/Documents/mantis-os/packages/backend/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023)
Exported variable 'createAuth' has or is using name 'SessionWithImpersonatedBy' from external module "/home/cole/Documents/mantis-os/packages/backend/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023)
Ctrl+click to open in new tab
Exported variable 'createAuth' has or is using name 'UserWithRole' from external module "/home/cole/Documents/mantis-os/packages/backend/node_modules/better-auth/dist/plugins/admin/index" but cannot be named.ts(4023)
now we have this...
Cole
ColeOP4w ago
GitHub
[Bug] [Bug] TS4023 error occurs after using the admin plugin · Iss...
Is this suited for github? Yes, this is suited for github To Reproduce auth.ts import { betterAuth } from &#39;better-auth&#39; import { admin } from &#39;better-auth/plugins&#39; export const auth...
erquhart
erquhart4w ago
Ah okay

Did you find this page helpful?