mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-17 22:27:19 +00:00
26 lines
788 B
TypeScript
26 lines
788 B
TypeScript
import { useEffect } from "react";
|
|
import { useLocation } from "wouter";
|
|
import { useMode } from "./use-mode";
|
|
import { canAccessRoute } from "@/shared/app-registry";
|
|
import { useToast } from "./use-toast";
|
|
|
|
export function useRouteGuard() {
|
|
const [location, setLocation] = useLocation();
|
|
const { mode, realm, loading } = useMode();
|
|
const { toast } = useToast();
|
|
|
|
useEffect(() => {
|
|
if (loading || !realm || !mode) return;
|
|
|
|
const canAccess = canAccessRoute(location, realm, mode);
|
|
|
|
if (!canAccess) {
|
|
toast({
|
|
title: "Access Denied",
|
|
description: `This feature requires ${realm === "foundation" ? "Corporation" : "Foundation"} realm`,
|
|
variant: "destructive",
|
|
});
|
|
setLocation("/");
|
|
}
|
|
}, [location, realm, mode, loading]);
|
|
}
|