feat(P21PWA2-1,P21PWA2-2,P21PWA2-3): 深链路由守卫/离线审批队列/SW缓存策略升级
这个提交包含在:
+12
-8
@@ -2,6 +2,7 @@ import type { PropsWithChildren } from "react";
|
||||
import { Navigate, useLocation } from "react-router-dom";
|
||||
import { useAuth } from "../auth/AuthContext";
|
||||
import { hasAnyPermission } from "../auth/permissions";
|
||||
import { isOfflineSnapshotAllowedPath } from "../pwa";
|
||||
|
||||
function FullPageLoading() {
|
||||
return (
|
||||
@@ -18,19 +19,22 @@ function toLoginRedirect(pathname: string, search: string, hash: string) {
|
||||
|
||||
export function RequireAuth({ children }: PropsWithChildren) {
|
||||
const location = useLocation();
|
||||
const { accessToken, me, ready, mustChangePassword } = useAuth();
|
||||
const { accessToken, me, ready, mustChangePassword, offlineAccessMode } = useAuth();
|
||||
|
||||
if (!ready) {
|
||||
return <FullPageLoading />;
|
||||
}
|
||||
|
||||
if (!accessToken || !me) {
|
||||
return (
|
||||
<Navigate
|
||||
to={toLoginRedirect(location.pathname, location.search, location.hash)}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
if (!me) {
|
||||
return <Navigate to={toLoginRedirect(location.pathname, location.search, location.hash)} replace />;
|
||||
}
|
||||
|
||||
if (!accessToken) {
|
||||
if (offlineAccessMode && isOfflineSnapshotAllowedPath(location.pathname)) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return <Navigate to={toLoginRedirect(location.pathname, location.search, location.hash)} replace />;
|
||||
}
|
||||
|
||||
if (mustChangePassword && location.pathname !== "/change-password") {
|
||||
|
||||
在新工单中引用
屏蔽一个用户