Add auth checks to et pages
This commit is contained in:
parent
b34ca64200
commit
18e63c22dd
@ -11,8 +11,29 @@ import {
|
|||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Success from "../../components/Success.js";
|
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 () {
|
export default function () {
|
||||||
|
useLoaderData<typeof loader>();
|
||||||
|
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const currentMonth = currentDate.getUTCMonth() + 1;
|
const currentMonth = currentDate.getUTCMonth() + 1;
|
||||||
|
@ -14,6 +14,20 @@ import {
|
|||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
|
|
||||||
export async function loader({ context }: { context: RequestContext }) {
|
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(
|
const etData = await context.env.D1.prepare(
|
||||||
"SELECT id, name, points, roblox_id FROM et_members;",
|
"SELECT id, name, points, roblox_id FROM et_members;",
|
||||||
).all();
|
).all();
|
||||||
|
@ -31,6 +31,15 @@ export async function loader({ context }: { context: RequestContext }) {
|
|||||||
status: 401,
|
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 now = new Date();
|
||||||
const monthEventList = await context.env.D1.prepare(
|
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 = ?;",
|
"SELECT answer, approved, created_by, day, details, id, month, pending, type, year FROM events WHERE month = ? AND year = ?;",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user