inferAdditionalFields not working

Attaching images showing that the auth type provided to the plugin contains all additional fields but it is never being inferred by the client.
No description
No description
No description
4 Replies
Ping
Ping3w ago
I think you're missing client plugins, like the adminClient() plugin.
frectonz
frectonz3w ago
can you also share your main auth config, a reproducible repo would also be handy in getting this issue fixed
Blizzy
BlizzyOP3w ago
Added that and good catch, but still not showing the onboarding field
import { betterAuth } from "better-auth";
import { prisma } from "@trekko/db/client";
import { admin, phoneNumber } from "better-auth/plugins";
import { expo } from "@better-auth/expo";
import twilio from "twilio";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { createId } from "@paralleldrive/cuid2";

const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID!;
const twilioAuthToken = process.env.TWILIO_AUTH_TOKEN!;
const verifyServiceSid = process.env.TWILIO_VERIFY_SERVICE_SID!;

const twilioClient = twilio(twilioAccountSid, twilioAuthToken);

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
user: {
additionalFields: {
onboardingComplete: {
type: "boolean",
required: true,
input: false,
defaultValue: () => false,
},
},
},
plugins: [
admin(),
phoneNumber({
sendOTP: async ({ phoneNumber, code }) => {
try {
const verification = await twilioClient.verify.v2
.services(verifyServiceSid)
.verifications.create({
to: phoneNumber,
channel: "sms",
customCode: code,
});
console.log(`Sent OTP to ${verification.to}`);
} catch (error: any) {
console.error(
`Error sending OTP to ${phoneNumber}: ${
error.code || error.message || "Unknown error"
}`
);
throw error;
}
},
signUpOnVerification: {
getTempEmail: (phoneNumber) => {
return `${phoneNumber}@trekkoapp.com`;
},
},
callbackOnVerification: async ({ phoneNumber, user }, request) => {
// TODO
},
}),
expo(),
],
trustedOrigins: ["trekko://"],
advanced: {
database: {
generateId: () => createId(),
},
},
});

export type Auth = typeof auth;
import { betterAuth } from "better-auth";
import { prisma } from "@trekko/db/client";
import { admin, phoneNumber } from "better-auth/plugins";
import { expo } from "@better-auth/expo";
import twilio from "twilio";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { createId } from "@paralleldrive/cuid2";

const twilioAccountSid = process.env.TWILIO_ACCOUNT_SID!;
const twilioAuthToken = process.env.TWILIO_AUTH_TOKEN!;
const verifyServiceSid = process.env.TWILIO_VERIFY_SERVICE_SID!;

const twilioClient = twilio(twilioAccountSid, twilioAuthToken);

export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql",
}),
user: {
additionalFields: {
onboardingComplete: {
type: "boolean",
required: true,
input: false,
defaultValue: () => false,
},
},
},
plugins: [
admin(),
phoneNumber({
sendOTP: async ({ phoneNumber, code }) => {
try {
const verification = await twilioClient.verify.v2
.services(verifyServiceSid)
.verifications.create({
to: phoneNumber,
channel: "sms",
customCode: code,
});
console.log(`Sent OTP to ${verification.to}`);
} catch (error: any) {
console.error(
`Error sending OTP to ${phoneNumber}: ${
error.code || error.message || "Unknown error"
}`
);
throw error;
}
},
signUpOnVerification: {
getTempEmail: (phoneNumber) => {
return `${phoneNumber}@trekkoapp.com`;
},
},
callbackOnVerification: async ({ phoneNumber, user }, request) => {
// TODO
},
}),
expo(),
],
trustedOrigins: ["trekko://"],
advanced: {
database: {
generateId: () => createId(),
},
},
});

export type Auth = typeof auth;
Here you go^
Blizzy
BlizzyOP3w ago
additionaly wanted to show type is correct on server but not allowing field set
No description

Did you find this page helpful?