feat: add public visibility

This commit is contained in:
Steven
2022-09-14 23:08:24 +08:00
parent 5a79304153
commit 469c841713
9 changed files with 81 additions and 27 deletions

View File

@ -1,5 +1,5 @@
import { useEffect } from "react";
import { Route, Routes, useNavigate } from "react-router-dom";
import { Route, Routes, useLocation, useNavigate } from "react-router-dom";
import { userService, workspaceService } from "./services";
import useLoading from "./hooks/useLoading";
import Only from "./components/common/OnlyWhen";
@ -9,11 +9,27 @@ import WorkspaceDetail from "./pages/WorkspaceDetail";
import UserDetail from "./pages/UserDetail";
import ShortcutRedirector from "./pages/ShortcutRedirector";
const pathnameWhitelist = [/\/.+?\/go\/.+/];
function App() {
const navigate = useNavigate();
const location = useLocation();
const pageLoadingStatus = useLoading();
useEffect(() => {
let needAuth = true;
for (const regexp of pathnameWhitelist) {
if (regexp.test(location.pathname)) {
needAuth = false;
break;
}
}
if (!needAuth) {
pageLoadingStatus.setFinish();
return;
}
userService.initialState().finally(() => {
if (!userService.getState().user) {
pageLoadingStatus.setFinish();