-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Outlet } from "react-router-dom"; | ||
|
||
const UserRouteLayout = () => { | ||
return ( | ||
<div className="p-50px"> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserRouteLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Header } from "antd/es/layout/layout"; | ||
import { Link, Outlet, useLocation } from "react-router-dom"; | ||
|
||
const AdminLayout = () => { | ||
const location = useLocation(); | ||
const selectedKey = location.pathname; | ||
|
||
const adminNavLinks = { | ||
"/admin/users": "Users", | ||
"/admin/challenges": "Challenges", | ||
"/admin/submissions/all": "Submissions", | ||
"/admin/settings": "Settings", | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Header className="bg-gray-800 text-white flex justify-between px-5"> | ||
<div className="flex"> | ||
{Object.entries(adminNavLinks).map(([link, text]) => ( | ||
<Link | ||
key={link} | ||
to={link} | ||
className={`text-gray-400 select-none px-4 inline-block ${ | ||
selectedKey.startsWith(link) | ||
? "bg-blue-600 text-white pointer-events-none" | ||
: "hover:text-gray-200" | ||
}`} | ||
> | ||
{text} | ||
</Link> | ||
))} | ||
</div> | ||
</Header> | ||
<div className="p-50px"> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdminLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Response, NextFunction, Request } from "express"; | ||
|
||
export function verifyIsAdmin(req: Request, res: Response, next: NextFunction) { | ||
if (!req.payload) | ||
throw new Error("This middleware should be used after verifyAccess middleware"); | ||
|
||
return req.payload.isAdmin ? next() : res.status(403).send("Forbidden"); | ||
} |