Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/(pages)/_components/ProtectedDisplay/ProtectedDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import getActiveUser from 'app/(pages)/_utils/getActiveUser';

export default async function ProtectedDisplay({
allowedRoles,
allowedUsers,
failRedirectRoute,
children,
}: {
allowedRoles: string[];
allowedUsers?: string[];
failRedirectRoute: string;
children: React.ReactNode;
}) {
const user = await getActiveUser(failRedirectRoute);

if (allowedUsers && !allowedUsers.includes(user.email)) {
redirect('/');
}

const authorized = allowedRoles.includes(user.role);

if (user.role === 'hacker') {
Expand Down
16 changes: 15 additions & 1 deletion app/(pages)/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ export default function AdminLayout({
}: {
children: React.ReactNode;
}) {
const adminEmail = process.env.HUB_ADMIN_EMAIL;

if (!adminEmail) {
console.warn(
'HUB_ADMIN_EMAIL environment variable is not set, no users will have access to the admin panel'
);
}

const parsedAdminEmail = adminEmail ? adminEmail : '';

return (
<ProtectedDisplay allowedRoles={['admin']} failRedirectRoute="/login">
<ProtectedDisplay
allowedRoles={['admin']}
allowedUsers={[parsedAdminEmail]}
failRedirectRoute="/login"
>
{children}
</ProtectedDisplay>
);
Expand Down