diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index c59fd85..e454898 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -12,7 +12,7 @@ export default async function Page() { return (
-

Admin Dashboard

+

Admin Dashboard

Welcome, administrator! You have special access privileges.

diff --git a/src/app/events/[id]/page.tsx b/src/app/events/[id]/page.tsx index 3ecdc16..750c7c3 100644 --- a/src/app/events/[id]/page.tsx +++ b/src/app/events/[id]/page.tsx @@ -39,19 +39,7 @@ export default async function EventPage({ params }: EventPageProps) { notFound(); } - // Map database fields to frontend expected fields - const eventData = result.data; - const event = { - id: eventData.id, - title: eventData.eventTitle, - content: eventData.eventDesc, - event_date: eventData.eventDate, - image_url: eventData.imageUrl, - created_at: eventData.createdAt, - updated_at: eventData.updatedAt, - user_id: eventData.createdBy, - }; - return ; + return ; } catch (error: unknown) { // Log the error for debugging purposes if (error instanceof Error) { diff --git a/src/components/events/event-detail.tsx b/src/components/events/event-detail.tsx index c92bea4..3cc0ce9 100644 --- a/src/components/events/event-detail.tsx +++ b/src/components/events/event-detail.tsx @@ -9,13 +9,13 @@ import MarkdownRenderer from "./markdown-renderer"; interface Event { id: string; - title: string; - content: string; - event_date: string; - image_url: string | null; - created_at: string; - updated_at: string; - user_id: string; + eventTitle: string; + eventDesc: string; + eventDate: string; + imageUrl: string | null; + createdAt: string; + updatedAt: string; + createdBy: string; } interface EventDetailProps { @@ -41,8 +41,8 @@ export default function EventDetail({ event }: EventDetailProps) { }); }; - const isUpcoming = new Date(event.event_date) > new Date(); - const isPast = new Date(event.event_date) < new Date(); + const isUpcoming = new Date(event.eventDate) > new Date(); + const isPast = new Date(event.eventDate) < new Date(); return (
@@ -60,7 +60,7 @@ export default function EventDetail({ event }: EventDetailProps) {

- {event.title} + {event.eventTitle}

{isUpcoming && ( @@ -83,23 +83,23 @@ export default function EventDetail({ event }: EventDetailProps) {
- {formatDate(event.event_date)} + {formatDate(event.eventDate)}
- {formatTime(event.event_date)} + {formatTime(event.eventDate)}
{/* Event Image */} - {event.image_url && ( + {event.imageUrl && (
{/* eslint-disable-next-line @next/next/no-img-element */} {event.title}
@@ -113,7 +113,7 @@ export default function EventDetail({ event }: EventDetailProps) { About This Event
- +
@@ -124,7 +124,7 @@ export default function EventDetail({ event }: EventDetailProps) {
Created:{" "} - {new Date(event.created_at).toLocaleDateString("en-US", { + {new Date(event.createdAt).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", @@ -132,7 +132,7 @@ export default function EventDetail({ event }: EventDetailProps) {
Last Updated:{" "} - {new Date(event.updated_at).toLocaleDateString("en-US", { + {new Date(event.updatedAt).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", diff --git a/src/middleware.ts b/src/middleware.ts index 6b307ce..8f37347 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -4,6 +4,7 @@ import type { NextRequest } from "next/server"; import { Ratelimit } from "@upstash/ratelimit"; import { Redis } from "@upstash/redis"; import { StandardResponse } from "./lib/types"; +import { headers } from "next/headers"; const redis = new Redis({ url: process.env.KV_REST_API_URL, @@ -22,19 +23,24 @@ const resetPasswordRatelimiter = new Ratelimit({ analytics: true, }); -const ALLOWED_ORIGIN = - process.env.NODE_ENV === "development" - ? "http://localhost:3000" - : "https://re-envision.org"; +const getHostName = async () => { + const headersList = await headers(); + return headersList.get("host"); +}; export async function middleware(request: NextRequest) { const { pathname } = request.nextUrl; + const allowedOrigin = + process.env.NODE_ENV === "development" + ? "http://localhost:3000" + : (await getHostName()) || ""; + if (request.method === "OPTIONS" && pathname.startsWith("/api")) { return new NextResponse(null, { status: 204, headers: { - "Access-Control-Allow-Origin": ALLOWED_ORIGIN, + "Access-Control-Allow-Origin": allowedOrigin, "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", }, @@ -45,6 +51,7 @@ export async function middleware(request: NextRequest) { const rateLimitResponse = await handleRateLimit( request, resetPasswordRatelimiter, + allowedOrigin, ); if (rateLimitResponse) { @@ -62,13 +69,17 @@ export async function middleware(request: NextRequest) { status: 500, headers: { "Content-Type": "application/json", - "Access-Control-Allow-Origin": ALLOWED_ORIGIN, + "Access-Control-Allow-Origin": allowedOrigin, "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", }, }); } else if (pathname.startsWith("/api")) { - const rateLimitResponse = await handleRateLimit(request, ratelimit); + const rateLimitResponse = await handleRateLimit( + request, + ratelimit, + allowedOrigin, + ); if (rateLimitResponse) { return rateLimitResponse; @@ -85,7 +96,7 @@ export async function middleware(request: NextRequest) { status: 500, headers: { "Content-Type": "application/json", - "Access-Control-Allow-Origin": ALLOWED_ORIGIN, + "Access-Control-Allow-Origin": allowedOrigin, "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", }, @@ -102,6 +113,7 @@ export const config = { const handleRateLimit = async ( request: NextRequest, ratelimiter: Ratelimit, + allowedOrigin: string, ): Promise => { const ip = request.headers.get("x-real-ip") ?? @@ -119,7 +131,7 @@ const handleRateLimit = async ( status: 429, headers: { "Content-Type": "application/json", - "Access-Control-Allow-Origin": ALLOWED_ORIGIN, + "Access-Control-Allow-Origin": allowedOrigin, "Access-Control-Allow-Methods": "POST, GET, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", "Retry-After": reset @@ -132,7 +144,7 @@ const handleRateLimit = async ( const response = NextResponse.next(); - response.headers.set("Access-Control-Allow-Origin", ALLOWED_ORIGIN); + response.headers.set("Access-Control-Allow-Origin", allowedOrigin); response.headers.set("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); response.headers.set("Access-Control-Allow-Headers", "Content-Type");