Consolidate authentication code

This commit is contained in:
april
2024-01-03 10:01:15 -06:00
parent 73b11482ff
commit 912e4d1b0e
12 changed files with 206 additions and 114 deletions

View File

@@ -1,6 +1,8 @@
import { TailfinAppShell } from "@/ui/nav/app-shell";
import { useAuth } from "@/util/auth";
import type { MetaFunction } from "@remix-run/node";
import { Outlet } from "@remix-run/react";
import { Outlet, useNavigate } from "@remix-run/react";
import { useEffect } from "react";
export const meta: MetaFunction = () => {
return [
@@ -10,11 +12,20 @@ export const meta: MetaFunction = () => {
};
export default function Index() {
const { user, loading } = useAuth();
const navigate = useNavigate();
useEffect(() => {
console.log("loading: " + loading);
console.log("user: " + user);
if (!loading && !user) {
navigate("/login");
}
}, [user, loading, navigate]);
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<TailfinAppShell>
<Outlet />
</TailfinAppShell>
</div>
<TailfinAppShell>
<Outlet />
</TailfinAppShell>
);
}