mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
* feat(web): improve session retrieval performance Switch to using `getServerSession` which avoids a HTTP round trip to retrieve session details. Additionally, migrate deprecated `app/lib/auth` calls to to `@calcom/lib` package. * fix: update failing test and lint * Consolidates auth code in features * Update yarn.lock * Update packages/trpc/server/createContext.ts * Oopsie --------- Co-authored-by: zomars <[email protected]>
14 lines
465 B
TypeScript
14 lines
465 B
TypeScript
import type { NextApiRequest } from "next";
|
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
|
|
import { getSession } from "./getSession";
|
|
|
|
type CtxOrReq = { req: NextApiRequest; ctx?: never } | { ctx: { req: NextApiRequest }; req?: never };
|
|
|
|
export const ensureSession = async (ctxOrReq: CtxOrReq) => {
|
|
const session = await getSession(ctxOrReq);
|
|
if (!session?.user.id) throw new HttpError({ statusCode: 401, message: "Unauthorized" });
|
|
return session;
|
|
};
|