MCPcopy Create free account
hub / github.com/better-auth/examples / RootComponent

Function RootComponent

tanstack-example/app/routes/__root.tsx:48–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46});
47
48function RootComponent() {
49 const [theme, setTheme] = useState<"light" | "dark">("light");
50 const { data, isPending, error } = useSession();
51 const { navigate } = useRouter();
52 console.log();
53
54 useEffect(() => {
55 if (!data?.user) {
56 if (!location.pathname.includes("auth/")) {
57 navigate({ to: "/auth/signin" });
58 }
59 } else {
60 navigate({ to: "/" });
61 }
62 setTheme(
63 window.matchMedia("(prefers-color-scheme: dark)").matches
64 ? "dark"
65 : "light",
66 );
67 }, [data, navigate]);
68
69 useEffect(() => {
70 const root = window.document.documentElement;
71
72 root.classList.remove("light", "dark");
73
74 root.classList.add(theme);
75 }, [theme]);
76
77 return (
78 <RootDocument>
79 <nav className="grid grid-cols-3 items-center w-full p-4">
80 <div className="flex items-center justify-center gap-2">
81 <svg
82 width="60"
83 height="45"
84 viewBox="0 0 60 45"
85 fill="none"
86 className="w-5 h-5"
87 xmlns="http://www.w3.org/2000/svg"
88 >
89 <title>Better Auth</title>
90 <path
91 fillRule="evenodd"
92 clipRule="evenodd"
93 d="M0 0H15V15H30V30H15V45H0V30V15V0ZM45 30V15H30V0H45H60V15V30V45H45H30V30H45Z"
94 className="fill-black dark:fill-white"
95 />
96 </svg>
97 <p>BETTER-AUTH</p>
98 <p>x</p>
99 <svg
100 className="w-5 h-5"
101 xmlns="http://www.w3.org/2000/svg"
102 width="45"
103 height="45"
104 viewBox="0 0 100 100"
105 fill="none"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected