Skip to content

[feature request] Ability to wait until client is ready #78

Description

@jamesarosen

@workos/authkit-react uses a natural React interface:

const { isLoading, user } = useAuth();

This works great for typical React components.

It doesn't work very well with frameworks like Tanstack-Router and React-Router that have lifecycle hooks for fetching data that run before the component renders.

It would be really nice to be able to do this:

export const Route = createFileRoute('/authenticated')({
  async beforeLoad({ context }) {
    const { clientReady } = context.auth; // the result of useAuth
    return clientReady.then((user) => {
      if (!user) {
        throw redirect({ to: '/auth/login' });
      }
    });
  },

  component:() => {
    const { isLoading, user } = useAuth();
    return "isLoading is never true here. User is always a user";
  },
});

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