diff --git a/app/routes/api.room.get.$roomId.tsx b/app/routes/api.room.get.$roomId.tsx
index 1e36b64..e20089d 100644
--- a/app/routes/api.room.get.$roomId.tsx
+++ b/app/routes/api.room.get.$roomId.tsx
@@ -31,9 +31,9 @@ export async function loader({ context, params, request }: LoaderFunctionArgs) {
});
if (!room) {
- return json("Room is Missing!", {
+ return json(undefined, {
status: 404,
- statusText: "BAD REQUEST!",
+ statusText: "NOT FOUND!",
});
}
diff --git a/app/routes/api.room.presence.get.$roomId.tsx b/app/routes/api.room.presence.get.$roomId.tsx
index 0f2e925..627f960 100644
--- a/app/routes/api.room.presence.get.$roomId.tsx
+++ b/app/routes/api.room.presence.get.$roomId.tsx
@@ -26,17 +26,6 @@ export async function loader({ context, params, request }: LoaderFunctionArgs) {
});
}
- const room = await db.query.rooms.findFirst({
- where: eq(rooms.id, roomId),
- });
-
- if (!room) {
- return json("Room is Missing!", {
- status: 404,
- statusText: "BAD REQUEST!",
- });
- }
-
const name = sessionClaims.name as string;
const image = sessionClaims.image as string;
const metadata = sessionClaims.metadata as {
diff --git a/app/routes/api.votes.get.$roomId.tsx b/app/routes/api.votes.get.$roomId.tsx
index 98f698b..4162adf 100644
--- a/app/routes/api.votes.get.$roomId.tsx
+++ b/app/routes/api.votes.get.$roomId.tsx
@@ -26,17 +26,6 @@ export async function loader({ context, params, request }: LoaderFunctionArgs) {
});
}
- const room = await db.query.rooms.findFirst({
- where: eq(rooms.id, roomId),
- });
-
- if (!room) {
- return json("Room is Missing!", {
- status: 404,
- statusText: "BAD REQUEST!",
- });
- }
-
return eventStream(request.signal, function setup(send) {
async function handler() {
const votesByRoomId = await db.query.votes.findMany({
diff --git a/app/routes/dashboard.tsx b/app/routes/dashboard.tsx
index 310f8fe..e05cf4a 100644
--- a/app/routes/dashboard.tsx
+++ b/app/routes/dashboard.tsx
@@ -13,7 +13,8 @@ export const loader: LoaderFunction = async (args) => {
if (!userId) {
return redirect("/sign-in");
}
- return {};
+
+ if (userId) return {};
};
type RoomsResponse =
diff --git a/app/routes/room.$roomId.tsx b/app/routes/room.$roomId.tsx
index 55c80ee..1289145 100644
--- a/app/routes/room.$roomId.tsx
+++ b/app/routes/room.$roomId.tsx
@@ -1,6 +1,6 @@
import { getAuth } from "@clerk/remix/ssr.server";
-import { LoaderFunction, redirect } from "@remix-run/node";
-import { Link, useParams } from "@remix-run/react";
+import { LoaderFunction, json, redirect } from "@remix-run/node";
+import { Link, useParams, useRouteError } from "@remix-run/react";
import {
CheckCircleIcon,
CopyIcon,
@@ -20,16 +20,67 @@ import { useEventSource } from "remix-utils/sse/react";
import { PresenceItem, RoomResponse, VoteResponse } from "~/services/types";
import { isAdmin, jsonToCsv } from "~/services/helpers";
import { useUser } from "@clerk/remix";
+import { db } from "~/services/db.server";
+import { rooms } from "~/services/schema";
+import { eq } from "drizzle-orm";
+import { shitList } from "~/services/consts";
+// Loader
export const loader: LoaderFunction = async (args) => {
- const { userId } = await getAuth(args);
+ const { userId, sessionClaims } = await getAuth(args);
if (!userId) {
return redirect("/sign-in");
}
+
+ const room = await db.query.rooms.findFirst({
+ where: eq(rooms.id, args.params.roomId as string),
+ });
+
+ if (!room) {
+ throw new Response(null, {
+ status: 404,
+ statusText: "Not Found",
+ });
+ }
+
+ let isShit = false;
+ const email = sessionClaims.email as string;
+
+ shitList.forEach((shitItem) => {
+ if (email.includes(shitItem)) {
+ isShit = true;
+ }
+ });
+
+ if (isShit) {
+ return redirect(
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ&pp=ygUXbmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXA%3D"
+ );
+ }
+
return {};
};
+// Checks for 404
+export function ErrorBoundary() {
+ return (
+
+ 4️⃣0️⃣4️⃣
+
+ Oops! This room does not appear to exist, or may have been deleted! 😢
+
+
+ Back to Home
+
+
+ );
+}
+
export default function Room() {
const { user } = useUser();
const params = useParams();
@@ -49,7 +100,9 @@ export default function Room() {
let roomFromDbParsed = (roomFromDb ? JSON.parse(roomFromDb!) : undefined) as
| RoomResponse
+ | null
| undefined;
+
let votesFromDbParsed = JSON.parse(votesFromDb!) as VoteResponse | undefined;
let presenceDateParsed = JSON.parse(presenceData!) as
| PresenceItem[]
@@ -62,24 +115,6 @@ export default function Room() {
// Handlers
// =================================
- async function getRoomHandler() {
- const response = await fetch(`/api/internal/room/${roomId}`, {
- cache: "no-cache",
- method: "GET",
- });
-
- return (await response.json()) as RoomResponse;
- }
-
- async function getVotesHandler() {
- const dbVotesResponse = await fetch(`/api/internal/room/${roomId}/votes`, {
- cache: "no-cache",
- method: "GET",
- });
- const dbVotes = (await dbVotesResponse.json()) as VoteResponse;
- return dbVotes;
- }
-
async function setVoteHandler(value: string) {
if (roomFromDb) {
await fetch(`/api/vote/set/${roomId}`, {
@@ -208,11 +243,11 @@ export default function Room() {
// UI
// =================================
// Room is loading
- if (roomFromDbParsed === null) {
+ if (!roomFromDbParsed) {
return