diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index 025779ed2b..0000000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -yarn pre-commit diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 246057aa0c..0000000000 --- a/.prettierrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("../../packages/config/prettier-preset"); diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index 2afcfd2404..0000000000 --- a/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"], -}; diff --git a/lib/helpers/verifyApiKey.ts b/lib/helpers/verifyApiKey.ts index 0ee197456c..0f70c88a8e 100644 --- a/lib/helpers/verifyApiKey.ts +++ b/lib/helpers/verifyApiKey.ts @@ -1,8 +1,17 @@ +import type { IncomingMessage } from "http"; +import type { NextApiRequest, NextApiResponse } from "next"; import { NextMiddleware } from "next-api-middleware"; import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys"; import prisma from "@calcom/prisma"; +/** @todo figure how to use the one from `@calcom/types`fi */ +declare module "next" { + export interface NextApiRequest extends IncomingMessage { + userId: number; + } +} + // Used to check if the API key is not expired, could be extracted if reused. but not for now. export const dateInPast = function (date: Date) { const now = new Date(); @@ -12,24 +21,21 @@ export const dateInPast = function (date: Date) { }; // This verifies the API key and sets the user if it is valid. -export const verifyApiKey: NextMiddleware = async (req, res, next) => { - if (!req.query.apiKey) res.status(401).json({ message: "No api key provided" }); +export const verifyApiKey: NextMiddleware = async (req: NextApiRequest, res: NextApiResponse, next) => { + if (!req.query.apiKey) return res.status(401).json({ message: "No api key provided" }); // We remove the prefix from the user provided api_key. If no env set default to "cal_" const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", ""); // Hash the key again before matching against the database records. const hashedKey = hashAPIKey(strippedApiKey); // Check if the hashed api key exists in database. - await prisma.apiKey.findUnique({ where: { hashedKey } }).then(async (apiKey) => { - // If we cannot find any api key. Throw a 401 Unauthorized. - if (!apiKey) res.status(401).json({ error: "Your api key is not valid" }); - if (apiKey && apiKey.expiresAt && dateInPast(apiKey.expiresAt) && apiKey.userId) { - // Right now API Keys are user centric, we only allow resources related to this userId throughout the application. - // if the api key is not expired, and the user id is present in the database. - // Set the user in the request. as x-calcom-user-id. - if (apiKey.userId) res.setHeader("X-Calcom-User-ID", apiKey.userId); - - // Pass the request to the next middleware. - await next(); - } - }); + const apiKey = await prisma.apiKey.findUnique({ where: { hashedKey } }); + // If we cannot find any api key. Throw a 401 Unauthorized. + if (!apiKey) return res.status(401).json({ error: "Your api key is not valid" }); + if (apiKey.expiresAt && dateInPast(apiKey.expiresAt)) { + return res.status(401).json({ error: "This api key is expired" }); + } + if (!apiKey.userId) return res.status(404).json({ error: "No user found for this api key" }); + /* We save the user id in the request for later use */ + req.userId = apiKey.userId; + await next(); }; diff --git a/lib/utils/getCalcomUserId.ts b/lib/utils/getCalcomUserId.ts deleted file mode 100644 index 8670bc8759..0000000000 --- a/lib/utils/getCalcomUserId.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { NextApiResponse } from "next"; - -export const getCalcomUserId = (res: NextApiResponse): number => res.getHeader("x-calcom-user-id") as number; diff --git a/package.json b/package.json index 16dc0f9b9f..5739292e02 100644 --- a/package.json +++ b/package.json @@ -14,24 +14,17 @@ "lint-fix": "next lint --fix && prettier --write .", "test": "jest --detectOpenHandles", "type-check": "tsc --pretty --noEmit", - "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", - "prepare": "husky install", - "pre-commit": "next lint" + "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" }, "devDependencies": { - "@babel/core": "^7.17.8", - "@babel/preset-env": "^7.16.11", - "@babel/preset-typescript": "^7.16.7", - "@calcom/prisma": "*", "@calcom/tsconfig": "*", "@typescript-eslint/eslint-plugin": "^5.16.0", "babel-jest": "^27.5.1", - "husky": "^7.0.4", "jest": "^27.5.1", - "node-mocks-http": "^1.11.0", - "prettier": "^2.6.1" + "node-mocks-http": "^1.11.0" }, "dependencies": { + "@calcom/prisma": "*", "@sentry/nextjs": "^6.19.3", "next": "^12.1.4", "next-api-middleware": "^1.0.1", diff --git a/pages/api/attendees/[id].ts b/pages/api/attendees/[id].ts index a7b573cc87..3eba0891f2 100644 --- a/pages/api/attendees/[id].ts +++ b/pages/api/attendees/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { AttendeeResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaAttendeeBodyParams, schemaAttendeePublic } from "@lib/validations/attendee"; import { schemaQueryIdParseInt, @@ -93,7 +92,7 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; // Here we make sure to only return attendee's of the user's own bookings. const userBookings = await prisma.booking.findMany({ where: { @@ -68,7 +67,7 @@ async function createOrlistAllAttendees( throw new Error("Invalid request body", safe.error); } const bookingId = safe.data.bookingId; - const userId = getCalcomUserId(res); + const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index bdb1215f74..546fbe0ce1 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { AvailabilityResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability"; import { schemaQueryIdParseInt, @@ -97,7 +96,7 @@ export async function availabilityById(req: NextApiRequest, res: NextApiResponse const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaAvailabilityBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = getCalcomUserId(res); + const userId = req.userId; const data = await prisma.availability.findMany({ where: { userId } }); const availabiltiesIds = data.map((availability) => availability.id); if (availabiltiesIds.includes(safeQuery.data.id)) { diff --git a/pages/api/availabilities/index.ts b/pages/api/availabilities/index.ts index 63ae75db49..a6310059f7 100644 --- a/pages/api/availabilities/index.ts +++ b/pages/api/availabilities/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { AvailabilityResponse, AvailabilitiesResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaAvailabilityBodyParams, schemaAvailabilityPublic } from "@lib/validations/availability"; /** @@ -47,7 +46,7 @@ async function createOrlistAllAvailabilities( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.availability.findMany({ where: { userId } }); diff --git a/pages/api/booking-references/[id].ts b/pages/api/booking-references/[id].ts index 9a1b40089b..1644041b2f 100644 --- a/pages/api/booking-references/[id].ts +++ b/pages/api/booking-references/[id].ts @@ -5,7 +5,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { BookingReferenceResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaBookingReferenceBodyParams, schemaBookingReferencePublic, @@ -98,7 +97,7 @@ export async function bookingReferenceById( const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaBookingReferenceBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = getCalcomUserId(res); + const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, diff --git a/pages/api/booking-references/index.ts b/pages/api/booking-references/index.ts index 9ceedeed30..03bc700596 100644 --- a/pages/api/booking-references/index.ts +++ b/pages/api/booking-references/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { BookingReferenceResponse, BookingReferencesResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaBookingReferenceBodyParams, schemaBookingReferencePublic, @@ -46,7 +45,7 @@ async function createOrlistAllBookingReferences( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, @@ -72,7 +71,7 @@ async function createOrlistAllBookingReferences( } // const booking_reference = schemaBookingReferencePublic.parse(data); - const userId = getCalcomUserId(res); + const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, include: { bookings: true }, diff --git a/pages/api/bookings/[id].ts b/pages/api/bookings/[id].ts index af6a379158..f40ae3ccbd 100644 --- a/pages/api/bookings/[id].ts +++ b/pages/api/bookings/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { BookingResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaBookingBodyParams, schemaBookingPublic } from "@lib/validations/booking"; import { schemaQueryIdParseInt, @@ -91,7 +90,7 @@ export async function bookingById(req: NextApiRequest, res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.booking.findMany({ where: { userId } }); diff --git a/pages/api/daily-event-references/[id].ts b/pages/api/daily-event-references/[id].ts index 089e21610b..993e47ed57 100644 --- a/pages/api/daily-event-references/[id].ts +++ b/pages/api/daily-event-references/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { DailyEventReferenceResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaDailyEventReferenceBodyParams, schemaDailyEventReferencePublic, @@ -97,7 +96,7 @@ export async function dailyEventReferenceById( const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaDailyEventReferenceBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = getCalcomUserId(res); + const userId = req.userId; const userBookings = await prisma.booking.findMany({ where: { userId } }); const userBookingIds = userBookings.map((booking) => booking.id); const userBookingDailyEventReferences = await prisma.dailyEventReference.findMany({ diff --git a/pages/api/daily-event-references/index.ts b/pages/api/daily-event-references/index.ts index 8b00334b1e..7b216d0040 100644 --- a/pages/api/daily-event-references/index.ts +++ b/pages/api/daily-event-references/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { DailyEventReferenceResponse, DailyEventReferencesResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaDailyEventReferenceBodyParams, schemaDailyEventReferencePublic, @@ -46,7 +45,7 @@ async function createOrlistAllDailyEventReferences( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; const userBookings = await prisma.booking.findMany({ where: { userId } }); const userBookingIds = userBookings.map((booking) => booking.id); diff --git a/pages/api/destination-calendars/[id].ts b/pages/api/destination-calendars/[id].ts index 62eb85810c..579ba83482 100644 --- a/pages/api/destination-calendars/[id].ts +++ b/pages/api/destination-calendars/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { DestinationCalendarResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaDestinationCalendarBodyParams, schemaDestinationCalendarPublic, @@ -97,7 +96,7 @@ export async function destionationCalendarById( const safeQuery = schemaQueryIdParseInt.safeParse(query); const safeBody = schemaDestinationCalendarBodyParams.safeParse(body); if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); - const userId = getCalcomUserId(res); + const userId = req.userId; const data = await prisma.destinationCalendar.findMany({ where: { userId } }); const userDestinationCalendars = data.map((destinationCalendar) => destinationCalendar.id); // FIXME: Should we also check ownership of bokingId and eventTypeId to avoid users cross-pollinating other users calendars. diff --git a/pages/api/destination-calendars/index.ts b/pages/api/destination-calendars/index.ts index 2b904dbc93..b3bdcaab57 100644 --- a/pages/api/destination-calendars/index.ts +++ b/pages/api/destination-calendars/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { DestinationCalendarResponse, DestinationCalendarsResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaDestinationCalendarBodyParams, schemaDestinationCalendarPublic, @@ -46,7 +45,7 @@ async function createOrlistAllDestinationCalendars( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.destinationCalendar.findMany({ where: { userId } }); diff --git a/pages/api/event-type-custom-inputs/[id].ts b/pages/api/event-type-custom-inputs/[id].ts index 5a00436361..5ff11ff884 100644 --- a/pages/api/event-type-custom-inputs/[id].ts +++ b/pages/api/event-type-custom-inputs/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { EventTypeCustomInputResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaEventTypeCustomInputBodyParams, schemaEventTypeCustomInputPublic, @@ -94,7 +93,7 @@ async function eventTypeById(req: NextApiRequest, res: NextApiResponse eventType.id); const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({ diff --git a/pages/api/event-type-custom-inputs/index.ts b/pages/api/event-type-custom-inputs/index.ts index e6c0c852bf..82c23f8593 100644 --- a/pages/api/event-type-custom-inputs/index.ts +++ b/pages/api/event-type-custom-inputs/index.ts @@ -45,7 +45,7 @@ async function createOrlistAllEventTypeCustomInputs( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; const data = await prisma.eventType.findMany({ where: { userId } }); const userEventTypes = data.map((eventType) => eventType.id); // const userEventTypeCustomInputs = await prisma.eventTypeCustomInput.findMany({ diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index dc7535cd5a..80d4f95bb6 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { EventTypeResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type"; import { schemaQueryIdParseInt, @@ -97,7 +96,7 @@ export async function eventTypeById(req: NextApiRequest, res: NextApiResponse eventType.id); if (userEventTypes.includes(safeQuery.data.id)) { diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index fc6a2a35f7..3135d9e866 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { EventTypeResponse, EventTypesResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaEventTypeBodyParams, schemaEventTypePublic } from "@lib/validations/event-type"; /** @@ -47,7 +46,7 @@ async function createOrlistAllEventTypes( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.eventType.findMany({ where: { userId } }); diff --git a/pages/api/memberships/[id].ts b/pages/api/memberships/[id].ts index df62f89107..4c90122f70 100644 --- a/pages/api/memberships/[id].ts +++ b/pages/api/memberships/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { MembershipResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaMembershipBodyParams, schemaMembershipPublic } from "@lib/validations/membership"; import { schemaQueryIdAsString, withValidQueryIdString } from "@lib/validations/shared/queryIdString"; @@ -108,7 +107,7 @@ export async function membershipById(req: NextApiRequest, res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.membership.findMany({ where: { userId } }); const memberships = data.map((membership) => schemaMembershipPublic.parse(membership)); diff --git a/pages/api/payments/[id].ts b/pages/api/payments/[id].ts index 295803ca76..9d7d28a184 100644 --- a/pages/api/payments/[id].ts +++ b/pages/api/payments/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { PaymentResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaPaymentPublic } from "@lib/validations/payment"; import { schemaQueryIdParseInt, @@ -38,7 +37,7 @@ import { export async function paymentById(req: NextApiRequest, res: NextApiResponse) { const { method, query } = req; const safeQuery = schemaQueryIdParseInt.safeParse(query); - const userId = getCalcomUserId(res); + const userId = req.userId; if (safeQuery.success && method === "GET") { const userWithBookings = await prisma.user.findUnique({ diff --git a/pages/api/payments/index.ts b/pages/api/payments/index.ts index bb2c132c0c..827bd68340 100644 --- a/pages/api/payments/index.ts +++ b/pages/api/payments/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { PaymentsResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaPaymentPublic } from "@lib/validations/payment"; /** @@ -24,8 +23,8 @@ import { schemaPaymentPublic } from "@lib/validations/payment"; * 404: * description: No payments were found */ -async function allPayments(_: NextApiRequest, res: NextApiResponse) { - const userId = getCalcomUserId(res); +async function allPayments(req: NextApiRequest, res: NextApiResponse) { + const userId = req.userId; const userWithBookings = await prisma.user.findUnique({ where: { id: userId }, diff --git a/pages/api/schedules/[id].ts b/pages/api/schedules/[id].ts index 1b46e62269..e0b83f106b 100644 --- a/pages/api/schedules/[id].ts +++ b/pages/api/schedules/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { ScheduleResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaScheduleBodyParams, schemaSchedulePublic } from "@lib/validations/schedule"; import { schemaQueryIdParseInt, @@ -91,7 +90,7 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse schedule.id); if (userScheduleIds.includes(safeQuery.data.id)) { diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts index cb4eeaeb9d..bbdd1c8dbc 100644 --- a/pages/api/schedules/index.ts +++ b/pages/api/schedules/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { ScheduleResponse, SchedulesResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaScheduleBodyParams, schemaSchedulePublic, withValidSchedule } from "@lib/validations/schedule"; /** @@ -43,7 +42,7 @@ async function createOrlistAllSchedules( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.schedule.findMany({ where: { userId } }); diff --git a/pages/api/selected-calendars/[id].ts b/pages/api/selected-calendars/[id].ts index 69cd9c059e..c2febd9c47 100644 --- a/pages/api/selected-calendars/[id].ts +++ b/pages/api/selected-calendars/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { SelectedCalendarResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaSelectedCalendarBodyParams, schemaSelectedCalendarPublic, @@ -132,7 +131,7 @@ export async function selectedCalendarById( if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error); // This is how we set the userId and externalId in the query for managing compoundId. const [paramUserId, integration, externalId] = safeQuery.data.id.split("_"); - const userId = getCalcomUserId(res); + const userId = req.userId; if (userId === parseInt(paramUserId)) { switch (method) { case "GET": diff --git a/pages/api/selected-calendars/index.ts b/pages/api/selected-calendars/index.ts index cb12a5dac7..0ccde36943 100644 --- a/pages/api/selected-calendars/index.ts +++ b/pages/api/selected-calendars/index.ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import { SelectedCalendarResponse, SelectedCalendarsResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaSelectedCalendarBodyParams, schemaSelectedCalendarPublic, @@ -46,7 +45,7 @@ async function createOrlistAllSelectedCalendars( res: NextApiResponse ) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const data = await prisma.selectedCalendar.findMany({ where: { userId } }); diff --git a/pages/api/teams/[id].ts b/pages/api/teams/[id].ts index de14a27c3d..69a3a7091f 100644 --- a/pages/api/teams/[id].ts +++ b/pages/api/teams/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { TeamResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt, @@ -91,7 +90,7 @@ export async function teamById(req: NextApiRequest, res: NextApiResponse) { const { method } = req; - const userId = getCalcomUserId(res); + const userId = req.userId; if (method === "GET") { const userWithMemberships = await prisma.membership.findMany({ where: { userId: userId }, diff --git a/pages/api/users/[id].ts b/pages/api/users/[id].ts index 5beaf442df..6dd4eb5f63 100644 --- a/pages/api/users/[id].ts +++ b/pages/api/users/[id].ts @@ -4,7 +4,6 @@ import prisma from "@calcom/prisma"; import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { UserResponse } from "@lib/types"; -import { getCalcomUserId } from "@lib/utils/getCalcomUserId"; import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt, @@ -91,7 +90,7 @@ export async function userById(req: NextApiRequest, res: NextApiResponse) { - const userId = getCalcomUserId(res); + const userId = req.userId; const data = await prisma.user.findMany({ where: { id: userId, diff --git a/tsconfig.json b/tsconfig.json index 5acb222ba6..4943d154a6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,19 @@ { - "extends": "@calcom/tsconfig/base.json", - "exclude": ["node_modules", "templates"], + "extends": "@calcom/tsconfig/nextjs.json", "compilerOptions": { - "strictNullChecks": true, "baseUrl": ".", - - "target": "es5", - "lib": ["dom", "dom.iterable", "esnext"], - "allowJs": true, - "noEmit": true, - "incremental": true, - "module": "esnext", - "resolveJsonModule": true, - "jsx": "preserve", "paths": { "@api/*": ["pages/api/*"], "@lib/*": ["lib/*"], "@/*": ["*"] } }, - "include": ["./**/*.ts*"] + "include": [ + "next-env.d.ts", + "../../packages/types/*.d.ts", + "../../packages/types/next-auth.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": ["node_modules", "templates"] }