Skip to content

Commit

Permalink
fix: route protection
Browse files Browse the repository at this point in the history
  • Loading branch information
gmat224 committed Dec 22, 2024
1 parent e284d1d commit f538e08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import AttendanceScreen from "./screens/AttendanceScreen.tsx";
import EventAttendanceSelectScreen from "./screens/EventAttendanceSelectScreen.tsx";
import { ExecRoute } from "@utils/AdminRouteProtection.tsx";
import { getUserMetaData } from "./api/apiRequests.ts";
import { UserRoute } from "@utils/UserRouteProtection.tsx";

//supertokens code
SuperTokens.init({
Expand Down Expand Up @@ -124,7 +125,11 @@ const router = createBrowserRouter(
/>
<Route
path="/signup/information"
element={<SignUpInformationScreen navbar={<Header />} />}
element={
<UserRoute>
<SignUpInformationScreen navbar={<Header />} />
</UserRoute>
}
/>
<Route
path="/admin/attendance/:id"
Expand Down
15 changes: 15 additions & 0 deletions web/src/utils/UserRouteProtection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { SessionAuth } from "supertokens-auth-react/recipe/session";
import ErrorScreen from "../screens/ErrorScreen";

export const UserRoute = (props: React.PropsWithChildren<any>) => {
return (
<SessionAuth
accessDeniedScreen={ErrorScreen}
overrideGlobalClaimValidators={(globalValidators) => [
...globalValidators,
]}
>
{props.children}
</SessionAuth>
);
};

0 comments on commit f538e08

Please sign in to comment.