How do I setup id when creating new users?

I am trying to use stripe plugin

databaseHooks: {
  user: {
    create: {
      before: async (user, context) => {
        // Generate user ID from email
        console.log("User before creation:", user);
        
                
        if (user.email) {
          const customId = generateUserId(user.email);
          
          return { 
            data: { 
              ...user, 
              id: customId
            },
            forceAllowId: true // This is required to allow custom IDs
          };
        }
        
        // If no email is available, let BetterAuth generate the ID
        return { data: user };
      },
      after: async (user) => {
        // Perform actions after user creation
        console.log("User after creation:", user);
      }
    },


2025-06-02T19:51:30.109Z WARN [Better Auth]: [Kysely Adapter] - You are trying to create a record with an id. This is not allowed as we handle id generation for you, unless you pass in the forceAllowId parameter. The id will be ignored.
Create method with
id
being called at:
at createWithHooks (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.XjdOGtZf.mjs:78:85)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.createOAuthUser (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.XjdOGtZf.mjs:158:27)
at async handleOAuthUserInfo (webpack-internal:///(rsc)/./node_modules/better-auth/dist/shared/better-auth.Dvh-YFwT.mjs:1285:14)
Was this page helpful?