Profile hard-guard: redirect /profile to /login when logged out
The account sub-pages were already protected via validateTokens; add a loader on the profile index so the hub itself bounces to /login when unauthenticated.
This commit is contained in:
parent
24449fe5e9
commit
207d46eefd
@ -1,4 +1,5 @@
|
||||
import { MetaFunction } from "@remix-run/node";
|
||||
import { MetaFunction, redirect, type LoaderFunctionArgs } from "@remix-run/node";
|
||||
import { sessionStorage } from "~/sessions.server";
|
||||
import {
|
||||
BookmarkMinus,
|
||||
ChevronLeft,
|
||||
@ -33,6 +34,19 @@ interface MenuItemType {
|
||||
hasBorder?: boolean;
|
||||
image: React.ReactNode;
|
||||
}
|
||||
// Guard: the account hub requires login (sub-pages are already protected via
|
||||
// validateTokens; this covers the /profile index itself).
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const session = await sessionStorage.getSession(
|
||||
request.headers.get("cookie")
|
||||
);
|
||||
const user = session.get("user");
|
||||
if (!user?.access_token) {
|
||||
throw redirect("/login");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function Profile() {
|
||||
const { user, theme: initialTheme } = useRootData();
|
||||
const [storeModalOpen, setStoreModalOpen] = useState(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user