2022-05-14 10:22:06 +00:00
|
|
|
import { useMatches } from "@remix-run/react";
|
|
|
|
|
2022-05-19 22:55:02 +00:00
|
|
|
import type { SessionData } from "~/utils/auth.server";
|
2022-05-14 10:22:06 +00:00
|
|
|
|
|
|
|
export default function useSession() {
|
|
|
|
const matches = useMatches();
|
|
|
|
const __appRoute = matches.find((match) => match.id === "routes/__app");
|
|
|
|
if (!__appRoute) {
|
|
|
|
throw new Error("useSession hook called outside _app route");
|
|
|
|
}
|
|
|
|
|
2022-05-19 22:55:02 +00:00
|
|
|
return __appRoute.data as SessionData;
|
2022-05-14 10:22:06 +00:00
|
|
|
}
|