fix(auth): redirect expired sessions before permission checks
This commit is contained in:
@@ -7,6 +7,7 @@ import type { ReactNode } from "react";
|
||||
|
||||
import { permissionForPath } from "@/lib/permissions";
|
||||
import { useAccessStore } from "@/store/accessStore";
|
||||
import { useAuthStore } from "@/store/authStore";
|
||||
|
||||
export const RoutePermissionGuard = ({
|
||||
children,
|
||||
@@ -16,8 +17,24 @@ export const RoutePermissionGuard = ({
|
||||
const pathname = usePathname();
|
||||
const permissions = useAccessStore((state) => state.permissions);
|
||||
const loading = useAccessStore((state) => state.loading);
|
||||
const sessionExpired = useAuthStore((state) => state.sessionExpired);
|
||||
const requiredPermission = permissionForPath(pathname);
|
||||
|
||||
if (sessionExpired) {
|
||||
return (
|
||||
<Box sx={{ p: 3 }}>
|
||||
<Alert severity="warning">
|
||||
<Stack spacing={0.5}>
|
||||
<Typography variant="body1">登录状态已失效</Typography>
|
||||
<Typography variant="body2">
|
||||
正在跳转到登录页面…
|
||||
</Typography>
|
||||
</Stack>
|
||||
</Alert>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
if (requiredPermission && loading) {
|
||||
return (
|
||||
<Box sx={{ minHeight: 320, display: "grid", placeItems: "center" }}>
|
||||
|
||||
Reference in New Issue
Block a user