Path: blob/main/components/dashboard/src/app/AdminRoute.tsx
2499 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useContext } from "react";7import { Redirect, Route } from "react-router";8import { UserContext } from "../user-context";9import { RoleOrPermission } from "@gitpod/public-api/lib/gitpod/v1/user_pb";1011// A wrapper for <Route> that redirects to the workspaces screen if the user isn't a admin.12// This wrapper only accepts the component property13export function AdminRoute({ component }: any) {14const { user } = useContext(UserContext);15return (16<Route17render={({ location }: any) =>18user?.rolesOrPermissions?.includes(RoleOrPermission.ADMIN) ? (19<Route component={component}></Route>20) : (21<Redirect22to={{23pathname: "/workspaces",24state: { from: location },25}}26/>27)28}29/>30);31}323334