Why useRouteData can return undefined?

In this example:
export function routeData({ params }: RouteDataArgs) {
  return createServerData$(
    async ([_, id], { request }) => {
      const user = await authenticator.isAuthenticated(request, {
        failureRedirect: "/",
      });

      if (!user.isAdmin) {
        throw redirect("/login");
      }

      return prisma.organisation.findUniqueOrThrow({
        where: { id },
      });
    },
    { key: () => ["organisation", params.orgId] }
  );
}

export default function AdminOrganisations() {
  const organisation = useRouteData<typeof routeData>();

  return (
    <>
      <Header>{organisation().name}</Header>
      <Container>...</Container>
    </>
  );
}

If I'm not an admin I'm redirected.
If no organisation is found with the
id
, prisma throw.
So I'm sure
const organisation
should be defined. But the type is still
const organisation: Resource<Organisation | undefined>

Why?
Was this page helpful?