관리자 기본 진입 경로 수정
This commit is contained in:
parent
778e8526d4
commit
bd046c4501
6 changed files with 62 additions and 25 deletions
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
import type { ReactNode } from "react";
|
||||
import { BrowserRouter, Navigate, Route, Routes, useLocation } from "react-router-dom";
|
||||
import { AuthProvider, canAccessRole, useAuth, roleHomePath, type AuthUser, type Role } from "./lib/auth";
|
||||
import { AuthProvider, canAccessRole, initialPathForUser, useAuth, roleHomePath, type AuthUser, type Role } from "./lib/auth";
|
||||
|
||||
import Login from "./pages/Login";
|
||||
import Onboarding from "./pages/Onboarding";
|
||||
|
|
@ -79,10 +79,7 @@ function isAdminWorkspacePath(path: string) {
|
|||
}
|
||||
|
||||
function approvedHomePath(user: AuthUser) {
|
||||
if (user.onboardingCompletedAt == null) {
|
||||
return canAccessRole(user, "admin") ? "/admin" : "/onboarding";
|
||||
}
|
||||
return roleHomePath(user.role);
|
||||
return initialPathForUser(user);
|
||||
}
|
||||
|
||||
function OnboardingGate({ children }: { children: ReactNode }) {
|
||||
|
|
@ -99,7 +96,7 @@ function OnboardingGate({ children }: { children: ReactNode }) {
|
|||
return <Navigate to="/onboarding" replace state={{ from: path }} />;
|
||||
}
|
||||
if (user && user.onboardingCompletedAt != null && (path === "/login" || path === "/onboarding")) {
|
||||
return <Navigate to={roleHomePath(user.role)} replace />;
|
||||
return <Navigate to={initialPathForUser(user)} replace />;
|
||||
}
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
|
@ -129,7 +126,7 @@ function RootRedirect() {
|
|||
if (user && user.onboardingCompletedAt == null) {
|
||||
return <Navigate to={approvedHomePath(user)} replace />;
|
||||
}
|
||||
return <Navigate to={user ? roleHomePath(user.role) : "/login"} replace />;
|
||||
return <Navigate to={user ? initialPathForUser(user) : "/login"} replace />;
|
||||
}
|
||||
|
||||
function AppRoutes() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue