Skip to content

Commit

Permalink
fix(login): Redirect after login based on user roles 2 (#1028)
Browse files Browse the repository at this point in the history
* check in dashboard loader func

* rm space

* extract
  • Loading branch information
tiffanyvu authored Jan 16, 2025
1 parent e4d0bd9 commit 4f03c81
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion react-app/src/features/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Plus as PlusIcon } from "lucide-react";
import { getUser, useGetUser } from "@/api";
import { WaiversList } from "./Lists/waivers";
import { SpasList } from "./Lists/spas";
import { UserRoles } from "shared-types";
import {
OsProvider,
type OsTab,
Expand Down Expand Up @@ -40,7 +41,14 @@ export const Dashboard = () => {
const { data: userObj } = useGetUser();
const osData = useOsData();

if (userObj === undefined) {
const isAbleToAccessDashboard = () => {
return (
userObj.user["custom:cms-roles"] &&
Object.values(UserRoles).some((role) => userObj.user["custom:cms-roles"].includes(role))
);
};

if (userObj === undefined || !isAbleToAccessDashboard()) {
return <Navigate to="/" />;
}

Expand Down

0 comments on commit 4f03c81

Please sign in to comment.