make session.user.name null

Hi I am porting my app to better auth and I currently use user.firstName + user.lastName instead of user.name

I managed to add the fields succesfully to the better auth setup and they are properly typed, the issue is since I am not using user.name I would like for it to be typed as null or undefined at least. I was wondering if that was possible of if I need to manually cast the types.

heres are the backend and frontend current implementations:

export function initAuth(options: {
  baseUrl: string;
  productionUrl: string;
  secret: string | undefined;
}) {
  const config = {
    user: {
      additionalFields: {
        firstName: {
          type: "string",
          required: true,
        },
        lastName: {
          type: "string",
          required: true,
        },
      },
    },
    database: drizzleAdapter(db, {
      provider: "mysql",
    }),
    baseURL: options.baseUrl,
    secret: options.secret,
    plugins: [expo()],
    emailAndPassword: {
      enabled: true,
      password: {
        hash: async (password: string) => {
          return await bcrypt.hash(password, 8);
        },
        verify: async (data: { hash: string; password: string }) => {
          return bcrypt.compare(data.password, data.hash);
        },
      },
    },

    trustedOrigins: ["expo://"],
  } satisfies BetterAuthOptions;

  return betterAuth(config);
}

export type Auth = ReturnType<typeof initAuth>;


export const authClient = createAuthClient({
  baseURL: getBaseUrl(),
  plugins: [
    expoClient({
      scheme: "expo",
      storagePrefix: "expo",
      storage: SecureStore,
    }),
    inferAdditionalFields<Auth>(),
  ],
});
Was this page helpful?