Create organisation after sign up is not working wihth soical sign-in

Hi, I'm trying to create an organisation with user database hooks. Creating an organisation is not working if the user tries to use social login in the login flow for the first time (where user creation happens in the user login flow).


 databaseHooks: {
    user: {
      create: {
        after: async (user) => {
          await auth.api.createOrganization({
            body: {
              name: `${user.name}'s Organization`,
              slug: `${Math.random().toString(36).substring(2, 15)}-${user.name}s-organization`,
              userId: user.id,
            },
          });
        },
      },
    },
    session: {
      create: {
        before: async (session) => {
          const memberRecord = await db.select({
            organizationId: members.organizationId,
          })
          .from(members)
          .where(eq(members.userId, session.userId))
          .limit(1);
        
          const organizationId = memberRecord.length > 0 ? memberRecord[0].organizationId : null;;

          return {
            data: {
              ...session,
              activeOrganizationId: organizationId,
            }
          }
        }
      }
    }
  }


Organisations created from this hook are not fetched with the admin organisation list.
Was this page helpful?