User additionalFields gives type errors because of not found #218

Closed
opened 2026-03-13 07:38:14 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @lucaslevin on GitHub (Nov 13, 2024).

Describe the bug
AdditionalFields are no longer accessible on user via. inferAdditionalFields(). It works fine in 0.7.5.

Expected behavior
AdditionalFields should be found on the user.

Originally created by @lucaslevin on GitHub (Nov 13, 2024). **Describe the bug** AdditionalFields are no longer accessible on user via. inferAdditionalFields<typeof auth>(). It works fine in 0.7.5. **Expected behavior** AdditionalFields should be found on the user.
Author
Owner

@Bekacru commented on GitHub (Nov 13, 2024):

Hey, when exactly is it not working? With my little tasting it's still working

@Bekacru commented on GitHub (Nov 13, 2024): Hey, when exactly is it not working? With my little tasting it's still working
Author
Owner

@lucaslevin commented on GitHub (Nov 13, 2024):

Can you try with this example? My client is not finding anything (I have a workspace/monorepo). I am trying to do useSession() to get the data from user, but the fields don't show up after 0.8+.

import { inferAdditionalFields } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";
import type { auth } from "./auth";
 
export const authClient = createAuthClient({
  plugins: [inferAdditionalFields<typeof auth>()],
});
@lucaslevin commented on GitHub (Nov 13, 2024): Can you try with this example? My client is not finding anything (I have a workspace/monorepo). I am trying to do useSession() to get the data from user, but the fields don't show up after 0.8+. ```typescript import { inferAdditionalFields } from "better-auth/client/plugins"; import { createAuthClient } from "better-auth/react"; import type { auth } from "./auth"; export const authClient = createAuthClient({ plugins: [inferAdditionalFields<typeof auth>()], }); ```
Author
Owner

@Bekacru commented on GitHub (Nov 13, 2024):

can you send me your auth.ts file (or something close)?

@Bekacru commented on GitHub (Nov 13, 2024): can you send me your auth.ts file (or something close)?
Author
Owner

@lucaslevin commented on GitHub (Nov 13, 2024):

import { admin, username } from 'better-auth/plugins';

import { betterAuth } from 'better-auth';
import { db } from '../../db';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';

export const auth = betterAuth({
  appName: 'App',
  baseURL: process.env.BETTER_AUTH_URL as string,
  database: drizzleAdapter(db, { provider: 'mysql' }),
  databaseHooks: {
    user: {
      create: {
        before: async (user) => {
          return { data: { ...user, role: user.email.includes('@exampe.com') ? 'admin' : 'user' } };
        },
      },
    },
  },
  emailAndPassword: { enabled: true },
  plugins: [admin(), username()],
  socialProviders: {
    gitlab: {
      clientId: process.env.GITLAB_CLIENT_ID as string,
      clientSecret: process.env.GITLAB_CLIENT_SECRET as string,
      issuer: process.env.GITLAB_ISSUER as string,
    },
  },
  trustedOrigins: [],
  user: {
    changeEmail: { enabled: true },
    additionalFields: {
      ageGroup: { type: 'string', required: false },
      startDate: { type: 'date', required: false },
      endDate: { type: 'date', required: false },
      muteNotifications: { type: 'boolean' },
      timeZone: { type: 'string', required: true },
    },
  },
});
@lucaslevin commented on GitHub (Nov 13, 2024): ```typescript import { admin, username } from 'better-auth/plugins'; import { betterAuth } from 'better-auth'; import { db } from '../../db'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; export const auth = betterAuth({ appName: 'App', baseURL: process.env.BETTER_AUTH_URL as string, database: drizzleAdapter(db, { provider: 'mysql' }), databaseHooks: { user: { create: { before: async (user) => { return { data: { ...user, role: user.email.includes('@exampe.com') ? 'admin' : 'user' } }; }, }, }, }, emailAndPassword: { enabled: true }, plugins: [admin(), username()], socialProviders: { gitlab: { clientId: process.env.GITLAB_CLIENT_ID as string, clientSecret: process.env.GITLAB_CLIENT_SECRET as string, issuer: process.env.GITLAB_ISSUER as string, }, }, trustedOrigins: [], user: { changeEmail: { enabled: true }, additionalFields: { ageGroup: { type: 'string', required: false }, startDate: { type: 'date', required: false }, endDate: { type: 'date', required: false }, muteNotifications: { type: 'boolean' }, timeZone: { type: 'string', required: true }, }, }, }); ```
Author
Owner

@lucaslevin commented on GitHub (Nov 13, 2024):

Ah.. my bad, I had cached a version of better-auth and it was conflicting ..

@lucaslevin commented on GitHub (Nov 13, 2024): Ah.. my bad, I had cached a version of better-auth and it was conflicting ..
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#218