import { LoadingOverlay } from "@mantine/core";
import { signOut } from "supertokens-web-js/recipe/passwordless";
import { redirect, createFileRoute } from "@tanstack/react-router";
import { defaultAuthData } from "@/contexts/auth-context";
import { playerKeys } from "@/features/players/queries";

export const Route = createFileRoute("/logout")({
  preload: false,
  loader: async ({ context }) => {
    await context.queryClient.setQueryData(playerKeys.auth, defaultAuthData);
    await signOut();
    throw redirect({ to: "/login" });
  },
  pendingComponent: () => <LoadingOverlay visible />,
});
