How to get client to immediately update activeOrganizationId after creating an organization?

Hello!

I have some code that redirects users to setup an organization after they first sign up
  const { data: session, isPending } = authClient.useSession();
  if (!isPending && !session?.session.activeOrganizationId) {
    redirect("/setup-organization");
  }


When they submit the organization form I call
        await authClient.organization.create({
          name: data.name.trim(),
          slug: generateSlug(data.name.trim()),
        });


I expected this to automatically update the session cookie w/ the activeOrganizationId although I found that not to be the case. However, even when I try to explicitly refresh the session before redirecting to the dashboard page it doesn't work
      await authClient.getSession({
        query: {
          disableCookieCache: true,
        },
      });


Only refreshing the page entirely gets activeOrganizationId in the session.

Is there any easy way to achieve what I want? What am I missing?

Thanks!
Was this page helpful?