Suggestion to add common additional fields as optional like a role to core tables #5

Closed
opened 2026-03-13 07:26:07 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @xcaeser on GitHub (Sep 28, 2024).

Referring to the docs:
Extending the Schema

can you add common columns as optional like roles (as an array), and other generic columns that can be populated on sign up/sign in and with a helper fn when needed?

Thank you

Originally created by @xcaeser on GitHub (Sep 28, 2024). Referring to the docs: [Extending the Schema](https://www.better-auth.com/#extending-the-schema) can you add common columns as optional like roles (as an array), and other generic columns that can be populated on sign up/sign in and with a helper fn when needed? Thank you
Author
Owner

@xcaeser commented on GitHub (Sep 28, 2024):

I just saw you can add fields to tables. this is awesome.
I added a role field.

would be nice to have an array type for roles for example

export const auth = betterAuth({
  database: {
    provider: "postgres", //change this to your database provider
    url: process.env.DATABASE_URL as string,
  },
  account: {
    accountLinking: {
      enabled: true,
    },
  },
  emailAndPassword: {
    enabled: true,
  },
  trustedOrigins: ["http://localhost:3000", "http://localhost:3001"],
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
      callbackUrl: "http://localhost:3000/auth/google/callback",
    },
  },
  plugins: [
    {
      id: "s-user",
      schema: {
        user: {
          fields: {
            role: {
              type: "string",
            },
          },
        },
      },
    },
  ],
  // Refer to the api documentation for more configuration options
});
@xcaeser commented on GitHub (Sep 28, 2024): I just saw you can add fields to tables. this is awesome. I added a role field. would be nice to have an array type for roles for example ```ts export const auth = betterAuth({ database: { provider: "postgres", //change this to your database provider url: process.env.DATABASE_URL as string, }, account: { accountLinking: { enabled: true, }, }, emailAndPassword: { enabled: true, }, trustedOrigins: ["http://localhost:3000", "http://localhost:3001"], socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, callbackUrl: "http://localhost:3000/auth/google/callback", }, }, plugins: [ { id: "s-user", schema: { user: { fields: { role: { type: "string", }, }, }, }, }, ], // Refer to the api documentation for more configuration options }); ```
Author
Owner

@Bekacru commented on GitHub (Oct 8, 2024):

closing this in favor of #121

@Bekacru commented on GitHub (Oct 8, 2024): closing this in favor of #121
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5