Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
printf "${{ secrets.CHECK_IN_CODE }}" | vercel env add CHECK_IN_CODE production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.TITO_API_TOKEN }}" | vercel env add TITO_API_TOKEN production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.OPENAI_API_KEY }}" | vercel env add OPENAI_API_KEY production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.HUB_ADMIN_EMAIL }}" | vercel env add HUB_ADMIN_EMAIL production --force --token=${{ secrets.VERCEL_TOKEN }}
Comment thread
michelleyeoh marked this conversation as resolved.

printf "${{ vars.ENV_URL }}" | vercel env add BASE_URL production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ vars.INVITE_DEADLINE }}" | vercel env add INVITE_DEADLINE production --force --token=${{ secrets.VERCEL_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
printf "${{ secrets.CHECK_IN_CODE }}" | vercel env add CHECK_IN_CODE production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.TITO_API_TOKEN }}" | vercel env add TITO_API_TOKEN production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.OPENAI_API_KEY }}" | vercel env add OPENAI_API_KEY production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ secrets.HUB_ADMIN_EMAIL }}" | vercel env add HUB_ADMIN_EMAIL production --force --token=${{ secrets.VERCEL_TOKEN }}
Comment thread
michelleyeoh marked this conversation as resolved.

printf "${{ vars.ENV_URL }}" | vercel env add BASE_URL production --force --token=${{ secrets.VERCEL_TOKEN }}
printf "${{ vars.INVITE_DEADLINE }}" | vercel env add INVITE_DEADLINE production --force --token=${{ secrets.VERCEL_TOKEN }}
Expand Down
13 changes: 13 additions & 0 deletions app/(pages)/_components/ProtectedDisplay/ProtectedDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ import getActiveUser from 'app/(pages)/_utils/getActiveUser';

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

if (allowedUser) {
const normalizedAllowedUser = allowedUser.trim().toLowerCase();
const userEmail = String(user.email ?? '')
.trim()
.toLowerCase();

if (!userEmail || normalizedAllowedUser !== userEmail) {
redirect(failRedirectRoute);
}
}

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

if (user.role === 'hacker') {
Expand Down
17 changes: 16 additions & 1 deletion app/(pages)/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@ 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'
);
}

// Assuming only one admin email
const parsedAdminEmail = adminEmail ? adminEmail : '';

Comment thread
michelleyeoh marked this conversation as resolved.
return (
<ProtectedDisplay allowedRoles={['admin']} failRedirectRoute="/login">
<ProtectedDisplay
allowedRoles={['admin']}
allowedUser={parsedAdminEmail}
failRedirectRoute="/login"
Comment thread
michelleyeoh marked this conversation as resolved.
>
Comment thread
michelleyeoh marked this conversation as resolved.
{children}
</ProtectedDisplay>
);
Expand Down
Loading