Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add auth checks to et pages
  • Loading branch information
regalijan committed Feb 26, 2024
1 parent b34ca64 commit 18e63c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/routes/book-event.tsx
Expand Up @@ -11,8 +11,29 @@ import {
} from "@chakra-ui/react";
import { useEffect, useState } from "react";
import Success from "../../components/Success.js";
import { useLoaderData } from "@remix-run/react";

export async function loader({ context }: { context: RequestContext }) {
if (!context.data.current_user)
throw new Response(null, {
status: 401,
});

if (
![1 << 3, 1 << 4, 1 << 12].find(
(p) => context.data.current_user.permissions & p,
)
)
throw new Response(null, {
status: 403,
});

return null;
}

export default function () {
useLoaderData<typeof loader>();

const toast = useToast();
const currentDate = new Date();
const currentMonth = currentDate.getUTCMonth() + 1;
Expand Down
14 changes: 14 additions & 0 deletions app/routes/et-members.tsx
Expand Up @@ -14,6 +14,20 @@ import {
} from "@chakra-ui/react";

export async function loader({ context }: { context: RequestContext }) {
if (!context.data.current_user)
throw new Response(null, {
status: 401,
});

if (
![1 << 3, 1 << 4, 1 << 12].find(
(p) => context.data.current_user.permissions & p,
)
)
throw new Response(null, {
status: 403,
});

const etData = await context.env.D1.prepare(
"SELECT id, name, points, roblox_id FROM et_members;",
).all();
Expand Down
9 changes: 9 additions & 0 deletions app/routes/events-team.tsx
Expand Up @@ -31,6 +31,15 @@ export async function loader({ context }: { context: RequestContext }) {
status: 401,
});

if (
![1 << 3, 1 << 4, 1 << 12].find(
(p) => context.data.current_user.permissions & p,
)
)
throw new Response(null, {
status: 403,
});

const now = new Date();
const monthEventList = await context.env.D1.prepare(
"SELECT answer, approved, created_by, day, details, id, month, pending, type, year FROM events WHERE month = ? AND year = ?;",
Expand Down

0 comments on commit 18e63c2

Please sign in to comment.