[GH-ISSUE #512] User additionalFields gives type errors because of not found #8302

Closed
opened 2026-04-13 03:22:35 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @lucaslevin on GitHub (Nov 13, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/512

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). Original GitHub issue: https://github.com/better-auth/better-auth/issues/512 **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.
GiteaMirror added the locked label 2026-04-13 03:22:35 -05:00
Author
Owner

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

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

<!-- gh-comment-id:2474219786 --> @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>()],
});
<!-- gh-comment-id:2474782715 --> @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)?

<!-- gh-comment-id:2474790994 --> @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 },
    },
  },
});
<!-- gh-comment-id:2474797986 --> @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 ..

<!-- gh-comment-id:2474959881 --> @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#8302