From 065a5c83fc73dd132a5a2d933fae66e918ce0cea Mon Sep 17 00:00:00 2001 From: atridadl Date: Mon, 27 Nov 2023 15:17:27 -0700 Subject: [PATCH] Shitlist changes --- .env.example | 4 ++-- app/components/FourOhFour.tsx | 11 +++++++++-- app/routes/api.room.get.$roomId.tsx | 6 +++--- app/routes/room.$roomId.tsx | 14 ++++---------- app/services/helpers.server.ts | 22 ++++++++++++++++++++++ remix.config.js | 4 ---- 6 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 app/services/helpers.server.ts diff --git a/.env.example b/.env.example index 620f20f..3b5fade 100644 --- a/.env.example +++ b/.env.example @@ -9,5 +9,5 @@ CLERK_PUBLISHABLE_KEY="" CLERK_SECRET_KEY="" CLERK_WEBHOOK_SIGNING_SECRET="" -# Misc -APP_ENV="" +#Misc +SHIT_LIST="" diff --git a/app/components/FourOhFour.tsx b/app/components/FourOhFour.tsx index ae2c593..dee574d 100644 --- a/app/components/FourOhFour.tsx +++ b/app/components/FourOhFour.tsx @@ -2,14 +2,21 @@ import { Link, isRouteErrorResponse, useRouteError } from "@remix-run/react"; export default function FourOhFour() { const error = useRouteError(); + + // Default errors + let status = 500; let message = - "Oops! This room does not appear to exist, or may have been deleted! šŸ˜¢"; + "Something wen't wrong! Please sign out, back in, and give it another try!"; + + // If error response is sent, use correct errors if (isRouteErrorResponse(error)) { message = error.statusText; + status = error.status; } + return ( -

4ļøāƒ£0ļøāƒ£4ļøāƒ£

+

Error {status}

{message}

If you believe you reached this page in error, please file an issue{" "} diff --git a/app/routes/api.room.get.$roomId.tsx b/app/routes/api.room.get.$roomId.tsx index e20089d..f847381 100644 --- a/app/routes/api.room.get.$roomId.tsx +++ b/app/routes/api.room.get.$roomId.tsx @@ -15,7 +15,7 @@ export async function loader({ context, params, request }: LoaderFunctionArgs) { if (!roomId) { return json("RoomId Missing!", { status: 400, - statusText: "BAD REQUEST!", + statusText: "The RoomId is Missing!", }); } @@ -31,9 +31,9 @@ export async function loader({ context, params, request }: LoaderFunctionArgs) { }); if (!room) { - return json(undefined, { + throw new Response(null, { status: 404, - statusText: "NOT FOUND!", + statusText: "NOT NOOOOOO!", }); } diff --git a/app/routes/room.$roomId.tsx b/app/routes/room.$roomId.tsx index 05be860..d7e7c8c 100644 --- a/app/routes/room.$roomId.tsx +++ b/app/routes/room.$roomId.tsx @@ -29,6 +29,7 @@ import { rooms } from "~/services/schema"; import { eq } from "drizzle-orm"; import { shitList } from "~/services/consts.server"; import FourOhFour from "~/components/FourOhFour"; +import { isShit } from "~/services/helpers.server"; // Loader export const loader: LoaderFunction = async (args) => { @@ -46,24 +47,17 @@ export const loader: LoaderFunction = async (args) => { throw new Response(null, { status: 404, statusText: - "Oops! This room does not appear to exist, or may have been deleted! šŸ˜¢", + "Oops! This room does not appear to exist, or may have been deleted!", }); } - let isShit = false; const email = sessionClaims.email as string; - shitList.forEach((shitItem) => { - if (email.includes(shitItem)) { - isShit = true; - } - }); - - if (isShit) { + if (isShit(email)) { throw new Response(null, { status: 404, statusText: - "Wowee zowee! This wasn't supposed to happen! Maybe try refreshing the page... šŸ¤”šŸ§", + "Wowee zowee! I'm sure I put that room around here somewhere...", }); } diff --git a/app/services/helpers.server.ts b/app/services/helpers.server.ts new file mode 100644 index 0000000..5a0bd62 --- /dev/null +++ b/app/services/helpers.server.ts @@ -0,0 +1,22 @@ +export const isShit = (email: string) => { + if (!process.env.SHIT_LIST) { + return false; + } + + const shitListString = process.env.SHIT_LIST as string; + const shitList = shitListString.split(","); + + let result = false; + + shitList.forEach((shitItem) => { + if (email.includes(shitItem)) { + console.log( + `šŸ”“ BLOCKED USEREMAIL: ${email}\nšŸ”“ FAILED CONDITION: ${shitItem}` + ); + + result = true; + } + }); + + return result; +}; diff --git a/remix.config.js b/remix.config.js index 7fac2d3..eec5a28 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,8 +1,4 @@ /** @type {import('@remix-run/dev').AppConfig} */ export default { ignoredRouteFiles: ["**/.*"], - // appDirectory: "app", - // assetsBuildDirectory: "public/build", - // publicPath: "/build/", - // serverBuildPath: "build/index.js", };