Skip to content

Creating Organization in triggers.user.onCreate #132

@brianwk

Description

@brianwk

When I create an organization using auth.api in the user onCreate trigger, I am getting the following TypeScript error:

Property 'id' does not exist on type '({ id: string; name: string; slug: string; createdAt: Date; logo?: string | null | undefined; metadata?: any; } & { metadata: Record<string, any> | undefined; members: ({ id: string; organizationId: string; userId: string; role: string; createdAt: Date; } | undefined)[]; }) | null'.

I must cast the return type to { id: string; name: string; slug: string; createdAt: Date; logo?: string | null | undefined; metadata?: any; } to get rid of the Type error.

    triggers: {
      user: {
        onCreate: async (ctx, user) => {
          const auth = createAuth(ctx);
          const authCtx = await auth.$context;
          const { id: organizationId } = (await auth.api.createOrganization({
            body: {
              userId: user._id,
              name: user.name,
              slug: user.username,
            },
          }));

Is there better way to createOrganization here I'm not seeing? I couldn't figure out how to run the internalAdapter of the organization plugin, for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions