blob: 51d924bed064da1a68b3a7b48d2b564c48f5801d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
"use client";
import { useEffect } from "react";
import { toast } from "sonner";
import { usePathname } from "next/navigation";
interface PermissionCheckerProps {
authorized: boolean;
message?: string;
}
export function PermissionChecker({ authorized, message }: PermissionCheckerProps) {
const pathname = usePathname();
useEffect(() => {
// Only show toast if authorization failed
if (!authorized) {
toast.error("Permission Denied", {
description: message || "You do not have permission to view this page. (Dev Mode: Viewing anyway)",
duration: 5000,
action: {
label: "Close",
onClick: () => toast.dismiss(),
},
});
} else {
// Optional: Show success toast only if explicitly needed,
// but usually we don't show toast for success to avoid noise.
// Uncomment for debugging:
toast.success("Authorized", { description: "Access granted.", duration: 5000 });
}
}, [authorized, message, pathname]);
return null;
}
|