feat(projects): get user info in router guard and remove in localStorage. close #459

This commit is contained in:
Soybean
2024-06-06 20:22:28 +08:00
parent 584cd54d6d
commit 5531a68641
4 changed files with 27 additions and 29 deletions

View File

@ -92,6 +92,7 @@ export function createRouteGuard(router: Router) {
* @param to to route
*/
async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw | null> {
const authStore = useAuthStore();
const routeStore = useRouteStore();
const notFoundRoute: RouteKey = 'not-found';
@ -125,6 +126,9 @@ async function initRoute(to: RouteLocationNormalized): Promise<RouteLocationRaw
// the auth route is initialized
// it is not the "not-found" route, then it is allowed to access
if (routeStore.isInitAuthRoute && !isNotFoundRoute) {
// update user info
await authStore.updateUserInfo();
return null;
}
// it is captured by the "not-found" route, then check whether the route exists