Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Add Unauthorized page
Browse files Browse the repository at this point in the history
  • Loading branch information
ALBERICLOOS committed Mar 16, 2024
1 parent 0ed88e0 commit 9736255
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
24 changes: 24 additions & 0 deletions frontend/src/components/DefaultErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {JSX} from "react";
import {BiError} from "react-icons/bi";

export default function DefaultErrorPage(title: string, body: string): JSX.Element {
return (
<div id="error-page" className={"container is-max-desktop mt-6"}>
<article className="message">
<div className="message-header has-background-danger-dark">
<span className="icon-text">
<span className="icon">
<i><BiError/></i>
</span>
<span>{title}</span>
</span>
</div>
<div className="message-body">
{body}
<br/>
<a href={"/"}>Go back to the homepage</a>
</div>
</article>
</div>
);
}
11 changes: 11 additions & 0 deletions frontend/src/components/authentication/Unauthorized.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {JSX} from "react";
import DefaultErrorPage from "../DefaultErrorPage.tsx";

export default function Unauthorized(): JSX.Element {
return (
DefaultErrorPage(
"Access to this page is restricted",
"Please check with an admin if you believe this is a mistake."
)
)
}
3 changes: 2 additions & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import HomeStudent from "./pages/student/HomeStudent.tsx";
import HomeTeacher from "./pages/teacher/HomeTeacher.tsx";
import ErrorPage from "./pages/error.tsx";
import studentLoader from "./dataloaders/StudentLoader.ts";
import Unauthorized from "./components/authentication/Unauthorized.tsx";

createRoot(document.getElementById('root')!).render(
<React.StrictMode>
Expand All @@ -21,7 +22,7 @@ createRoot(document.getElementById('root')!).render(
<Routes>
{/* Public routes */}
<Route path={"/login"} element={<LoginScreen/>}/>
<Route path={"/unauthorized"} element={<header>Unauthorized</header>}/>
<Route path={"/unauthorized"} element={<Unauthorized/>}/>

{/* Protected routes */}
<Route element={<RequireAuth allowedRoles={['ADMIN', 'STUDENT', 'TEACHER']}/>}>
Expand Down

0 comments on commit 9736255

Please sign in to comment.