Skip to content

Commit 61b3ed9

Browse files
committed
feat: 添加initAuth的hook
1 parent 3441fd3 commit 61b3ed9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/features/auth/initAuth.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import type { RouterContextType } from '@/features/router';
2+
import { useInitAuthRoutes } from '@/features/router';
3+
4+
const { VITE_AUTH_ROUTE_MODE, VITE_STATIC_SUPER_ROLE } = import.meta.env;
5+
16
export function useInitAuth() {
2-
if (authRouteMode === 'static') {
3-
dispatch(initStaticAuthRoute());
4-
} else {
5-
await dispatch(initDynamicAuthRoute());
6-
}
7-
const routeHomeName = getRouteHome(getState());
7+
const { initAuthRoutes } = useInitAuthRoutes();
88

9-
const homeRoute = router.getRouteByName(routeHomeName);
9+
function initAuth(roles: string[], addRoutes: RouterContextType['addRoutes']) {
10+
const isStaticSuper = VITE_AUTH_ROUTE_MODE === 'static' && roles.includes(VITE_STATIC_SUPER_ROLE);
11+
12+
if (isStaticSuper) {
13+
initAuthRoutes(isStaticSuper, roles, addRoutes);
14+
}
15+
}
1016

11-
if (homeRoute) dispatch(initHomeTab({ homeRouteName: routeHomeName as LastLevelRouteKey, route: homeRoute }));
17+
return {
18+
initAuth
19+
};
1220
}

0 commit comments

Comments
 (0)