Cannot set additionalField when calling signUp.email

I'm trying to pass a referredBy field during user registration using signUp.email, but TypeScript is rejecting it with the following error: "Object literal may only specify known properties, and 'referredBy' does not exist in type " 1. I've properly configured referredBy in my auth.ts configuration:
user: {
additionalFields: {
referredBy: {
type: "string",
required: false,
},
// other fields...
}
}
user: {
additionalFields: {
referredBy: {
type: "string",
required: false,
},
// other fields...
}
}
2. In my RegisterForm.tsx, I'm trying to pass the field like this:
await signUp.email({
email: values.email,
password: values.password,
name: values.name,
referredBy: typeof window !== "undefined" ? localStorage.getItem("referredBy") : null,
});
await signUp.email({
email: values.email,
password: values.password,
name: values.name,
referredBy: typeof window !== "undefined" ? localStorage.getItem("referredBy") : null,
});
Solution:
I had plugins indented
Jump to solution
25 Replies
RadiantFrog
RadiantFrogOP•2w ago
My auth-client looks like this
import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "auth";

export const { signIn, signUp, deleteUser, signOut, useSession } = createAuthClient({
baseURL: import.meta.env.VITE_BETTER_AUTH_URL,
user: {
plugins: [inferAdditionalFields<typeof auth>()],
},
});
import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "auth";

export const { signIn, signUp, deleteUser, signOut, useSession } = createAuthClient({
baseURL: import.meta.env.VITE_BETTER_AUTH_URL,
user: {
plugins: [inferAdditionalFields<typeof auth>()],
},
});
Ping
Ping•2w ago
Are you sure you're importing auth correctly? usually local import pathnames are ./auth
RadiantFrog
RadiantFrogOP•2w ago
yes the absolute path resolves correctly for "auth"
Ping
Ping•2w ago
From what you provided, it looks fine to me. Do you think you can show me your whole auth.ts file?
RadiantFrog
RadiantFrogOP•2w ago
import { betterAuth } from "better-auth";
import { convexAdapter } from "@better-auth-kit/convex";
import { ConvexHttpClient } from "convex/browser";
import { APP_NAME, DEFAULT_AVATAR, DEFAULT_LANGUAGE } from "@/config/constants";

const convexClient = new ConvexHttpClient(import.meta.env.VITE_CONVEX_URL);

export const AUTH_PROVIDERS = {
CREDENTIAL: "credential",
APPLE: "apple",
GOOGLE: "google",
} as const;

export const auth = betterAuth({
appName: APP_NAME,
secret: import.meta.env.BETTER_AUTH_SECRET,
database: convexAdapter(convexClient),
plugins: [],
account: {
accountLinking: {
enabled: true,
trustedProviders: [AUTH_PROVIDERS.GOOGLE, AUTH_PROVIDERS.APPLE, AUTH_PROVIDERS.CREDENTIAL],
},
},
user: {
changeEmail: {
enabled: true,
},
deleteUser: {
enabled: true,
},
additionalFields: {
avatar: {
type: "string",
required: false,
defaultValue: DEFAULT_AVATAR,
},
biography: {
type: "string",
required: false,
},
language: {
type: "string",
required: false,
defaultValue: DEFAULT_LANGUAGE,
},
providerId: {
type: "string",
required: false,
defaultValue: AUTH_PROVIDERS.CREDENTIAL,
},
referredBy: {
type: "string",
required: false,
},
},
},
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
autoSignIn: true,
},
});
import { betterAuth } from "better-auth";
import { convexAdapter } from "@better-auth-kit/convex";
import { ConvexHttpClient } from "convex/browser";
import { APP_NAME, DEFAULT_AVATAR, DEFAULT_LANGUAGE } from "@/config/constants";

const convexClient = new ConvexHttpClient(import.meta.env.VITE_CONVEX_URL);

export const AUTH_PROVIDERS = {
CREDENTIAL: "credential",
APPLE: "apple",
GOOGLE: "google",
} as const;

export const auth = betterAuth({
appName: APP_NAME,
secret: import.meta.env.BETTER_AUTH_SECRET,
database: convexAdapter(convexClient),
plugins: [],
account: {
accountLinking: {
enabled: true,
trustedProviders: [AUTH_PROVIDERS.GOOGLE, AUTH_PROVIDERS.APPLE, AUTH_PROVIDERS.CREDENTIAL],
},
},
user: {
changeEmail: {
enabled: true,
},
deleteUser: {
enabled: true,
},
additionalFields: {
avatar: {
type: "string",
required: false,
defaultValue: DEFAULT_AVATAR,
},
biography: {
type: "string",
required: false,
},
language: {
type: "string",
required: false,
defaultValue: DEFAULT_LANGUAGE,
},
providerId: {
type: "string",
required: false,
defaultValue: AUTH_PROVIDERS.CREDENTIAL,
},
referredBy: {
type: "string",
required: false,
},
},
},
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
autoSignIn: true,
},
});
@Ping
Ping
Ping•2w ago
Can you remove plugins: []? Sometimes that can mess up types
RadiantFrog
RadiantFrogOP•2w ago
no luck 😦 it is possible right to add the additional fields into signUp.email({})? because I want to set the referredBy when signing up
Ping
Ping•2w ago
Yeah what you're doing is right, when I test on my end, it works.
No description
Ping
Ping•2w ago
Some random strange thing is blocking the types for some reason.
RadiantFrog
RadiantFrogOP•2w ago
yes very strange. How does your auth-client.ts look like?
Ping
Ping•2w ago
import { createAuthClient } from "better-auth/react";
import type { auth } from "./auth.ts";
import { inferAdditionalFields } from "better-auth/client/plugins";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [inferAdditionalFields<typeof auth>()],
});

authClient.signUp.email({
name: "John Doe",
password: "password",
referredBy: "123",
});
import { createAuthClient } from "better-auth/react";
import type { auth } from "./auth.ts";
import { inferAdditionalFields } from "better-auth/client/plugins";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [inferAdditionalFields<typeof auth>()],
});

authClient.signUp.email({
name: "John Doe",
password: "password",
referredBy: "123",
});
RadiantFrog
RadiantFrogOP•2w ago
ah thanks I see the issue
Solution
RadiantFrog
RadiantFrog•2w ago
I had plugins indented
Ping
Ping•2w ago
Oh my goodness!
RadiantFrog
RadiantFrogOP•2w ago
user: {
plugins: [inferAdditionalFields<typeof auth>()],
},
user: {
plugins: [inferAdditionalFields<typeof auth>()],
},
Ping
Ping•2w ago
XD I didn't catch that
RadiantFrog
RadiantFrogOP•2w ago
thanks so much 🙂
Ping
Ping•2w ago
I wonder why it didn't give you type errs here tho 🤔
RadiantFrog
RadiantFrogOP•2w ago
No description
RadiantFrog
RadiantFrogOP•2w ago
yeah it allowed me to do that 😛
Ping
Ping•2w ago
huh, well, that's unlucky I guess 🤣 Anyway, I'm glad it's solved.
RadiantFrog
RadiantFrogOP•2w ago
🙂 amazing! Also love better-auth-kit, I'm using it with convex do you think it will work with the stripe plugin in that setup as well?
Ping
Ping•2w ago
I saw that 🔥🔥 How is convex adapter going for you? Any troubles with it? I'm honestly not sure, I haven't tested it 👀
RadiantFrog
RadiantFrogOP•2w ago
Very smooth 🙂 Roadmap looks good too. If it could also generate the schema for me that would save some time.
Ping
Ping•2w ago
Awesome! Good to hear :) If you do run into any issues regarding the adapter, just LMK!

Did you find this page helpful?