From 6a5eac649a7db560118464b2525117c704e229b9 Mon Sep 17 00:00:00 2001 From: Tim Raderschad Date: Wed, 4 Sep 2024 12:26:48 +0200 Subject: [PATCH] fix(web): clean up api --- apps/web/src/api/helpers.ts | 23 +++------------------- apps/web/src/api/index.ts | 3 +-- apps/web/src/api/routes/v1_project_data.ts | 4 ---- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/apps/web/src/api/helpers.ts b/apps/web/src/api/helpers.ts index ec39582c..6cb78f84 100644 --- a/apps/web/src/api/helpers.ts +++ b/apps/web/src/api/helpers.ts @@ -1,29 +1,12 @@ import { env } from "env/server.mjs"; -import type { Context, MiddlewareHandler } from "hono"; +import type { MiddlewareHandler } from "hono"; import { getCookie } from "hono/cookie"; -import type { GetServerSidePropsContext } from "next"; -import type { DefaultSession } from "next-auth"; +import type { Session } from "next-auth"; import { decode } from "next-auth/jwt"; -import { getServerAuthSession } from "server/common/get-server-auth-session"; -import type { UserSession } from "types/next-auth"; - -export async function getHonoSession(c: Context) { - return await getServerAuthSession({ - req: { - ...c.req.raw.clone(), - cookies: getCookie(c), - } as unknown as GetServerSidePropsContext["req"], - res: { - ...c.res, - getHeader: (h: string) => c.req.header(h), - setHeader: (h: string, v: string) => c.header(h, v), - } as unknown as GetServerSidePropsContext["res"], - }); -} export const authMiddleware: MiddlewareHandler<{ Variables: { - user: UserSession & DefaultSession["user"]; + user: NonNullable; }; }> = async (c, next) => { const tokenCookie = getCookie( diff --git a/apps/web/src/api/index.ts b/apps/web/src/api/index.ts index 5dec4ab5..cae76105 100644 --- a/apps/web/src/api/index.ts +++ b/apps/web/src/api/index.ts @@ -2,7 +2,6 @@ import { makeConfigRoute } from "api/routes/v1_config"; import { makeProjectDataRoute } from "api/routes/v1_project_data"; import { Hono } from "hono"; import { cors } from "hono/cors"; -import { logger } from "hono/logger"; import { makeHealthRoute } from "./routes/health"; import { makeIntegrationsRoute } from "./routes/integrations"; import { makeLegacyProjectDataRoute } from "./routes/legacy_project_data"; @@ -11,7 +10,7 @@ import { makeEventRoute } from "./routes/v1_event"; export const app = new Hono() .basePath("/api") // base middleware - .use("*", logger()) + .use("*", cors({ origin: "*", maxAge: 86400 })) .route("/health", makeHealthRoute()) // legacy routes diff --git a/apps/web/src/api/routes/v1_project_data.ts b/apps/web/src/api/routes/v1_project_data.ts index ac29565b..9ca5bfb1 100644 --- a/apps/web/src/api/routes/v1_project_data.ts +++ b/apps/web/src/api/routes/v1_project_data.ts @@ -80,10 +80,6 @@ export function makeProjectDataRoute() { const app = new Hono() .get( "/:projectId", - cors({ - origin: "*", - maxAge: 86400, - }), zValidator( "query", z.object({