From 2f1ede9bcddd22287539e31af587bd00148fa644 Mon Sep 17 00:00:00 2001 From: Alex Johansson Date: Fri, 3 Sep 2021 22:51:21 +0200 Subject: [PATCH] use `getSession()` from `@lib/auth` everywhere (#563) --- pages/api/availability/eventtype.ts | 2 +- pages/api/availability/week.ts | 2 +- pages/api/book/confirm.ts | 2 +- pages/api/integrations/caldav/add.ts | 2 +- pages/api/integrations/zoomvideo/callback.ts | 2 +- pages/api/schedule/index.ts | 2 +- pages/api/teams.ts | 2 +- pages/api/teams/[team]/index.ts | 2 +- pages/api/teams/[team]/invite.ts | 2 +- pages/api/teams/[team]/membership.ts | 2 +- pages/api/user/[id].ts | 2 +- pages/api/user/membership.ts | 2 +- pages/api/user/profile.ts | 2 +- pages/auth/forgot-password/index.tsx | 3 ++- pages/auth/login.tsx | 3 ++- pages/availability/index.tsx | 3 ++- pages/availability/troubleshoot.tsx | 2 +- pages/bookings/index.tsx | 3 ++- pages/event-types/[type].tsx | 2 +- pages/event-types/index.tsx | 3 ++- pages/integrations/[integration].tsx | 3 ++- pages/integrations/index.tsx | 3 ++- pages/settings/billing.tsx | 2 +- pages/settings/embed.tsx | 3 ++- pages/settings/password.tsx | 3 ++- pages/settings/profile.tsx | 2 +- pages/settings/teams.tsx | 3 ++- 27 files changed, 37 insertions(+), 27 deletions(-) diff --git a/pages/api/availability/eventtype.ts b/pages/api/availability/eventtype.ts index 71aab6ae..2125d47f 100644 --- a/pages/api/availability/eventtype.ts +++ b/pages/api/availability/eventtype.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "@lib/prisma"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/availability/week.ts b/pages/api/availability/week.ts index f0cd408e..2ac55c0c 100644 --- a/pages/api/availability/week.ts +++ b/pages/api/availability/week.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "../../../lib/prisma"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/book/confirm.ts b/pages/api/book/confirm.ts index 54bc7552..f84dd1ae 100644 --- a/pages/api/book/confirm.ts +++ b/pages/api/book/confirm.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "../../../lib/prisma"; import { handleLegacyConfirmationMail } from "./[user]"; import { CalendarEvent } from "@lib/calendarClient"; diff --git a/pages/api/integrations/caldav/add.ts b/pages/api/integrations/caldav/add.ts index 06b2bddd..2c848b20 100644 --- a/pages/api/integrations/caldav/add.ts +++ b/pages/api/integrations/caldav/add.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "../../../../lib/prisma"; import { symmetricEncrypt } from "@lib/crypto"; import logger from "@lib/logger"; diff --git a/pages/api/integrations/zoomvideo/callback.ts b/pages/api/integrations/zoomvideo/callback.ts index fb379cbb..5a15cc96 100644 --- a/pages/api/integrations/zoomvideo/callback.ts +++ b/pages/api/integrations/zoomvideo/callback.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "../../../../lib/prisma"; const client_id = process.env.ZOOM_CLIENT_ID; diff --git a/pages/api/schedule/index.ts b/pages/api/schedule/index.ts index 8b3e088a..651989dd 100644 --- a/pages/api/schedule/index.ts +++ b/pages/api/schedule/index.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma from "@lib/prisma"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/teams.ts b/pages/api/teams.ts index b386832f..b189b6a9 100644 --- a/pages/api/teams.ts +++ b/pages/api/teams.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "../../lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import slugify from "@lib/slugify"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/teams/[team]/index.ts b/pages/api/teams/[team]/index.ts index 62430423..33f16ef3 100644 --- a/pages/api/teams/[team]/index.ts +++ b/pages/api/teams/[team]/index.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "../../../../lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req: req }); diff --git a/pages/api/teams/[team]/invite.ts b/pages/api/teams/[team]/invite.ts index 3b7cdf64..e16526c3 100644 --- a/pages/api/teams/[team]/invite.ts +++ b/pages/api/teams/[team]/invite.ts @@ -1,7 +1,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "../../../../lib/prisma"; import createInvitationEmail from "../../../../lib/emails/invitation"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import { randomBytes } from "crypto"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/api/teams/[team]/membership.ts b/pages/api/teams/[team]/membership.ts index 8cd437e4..300e06de 100644 --- a/pages/api/teams/[team]/membership.ts +++ b/pages/api/teams/[team]/membership.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "../../../../lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req }); diff --git a/pages/api/user/[id].ts b/pages/api/user/[id].ts index 5eed37fd..d1598dd7 100644 --- a/pages/api/user/[id].ts +++ b/pages/api/user/[id].ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "@lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req: req }); diff --git a/pages/api/user/membership.ts b/pages/api/user/membership.ts index de48fcf5..e307a1ae 100644 --- a/pages/api/user/membership.ts +++ b/pages/api/user/membership.ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import prisma from "../../../lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { const session = await getSession({ req: req }); diff --git a/pages/api/user/profile.ts b/pages/api/user/profile.ts index fbc13c7d..2c3f9305 100644 --- a/pages/api/user/profile.ts +++ b/pages/api/user/profile.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import prisma, { whereAndSelect } from "@lib/prisma"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { diff --git a/pages/auth/forgot-password/index.tsx b/pages/auth/forgot-password/index.tsx index fd2a90aa..4025a5be 100644 --- a/pages/auth/forgot-password/index.tsx +++ b/pages/auth/forgot-password/index.tsx @@ -1,8 +1,9 @@ import { HeadSeo } from "@components/seo/head-seo"; import Link from "next/link"; import React from "react"; -import { getCsrfToken, getSession } from "next-auth/client"; +import { getCsrfToken } from "next-auth/client"; import debounce from "lodash.debounce"; +import { getSession } from "@lib/auth"; export default function ForgotPassword({ csrfToken }) { const [loading, setLoading] = React.useState(false); diff --git a/pages/auth/login.tsx b/pages/auth/login.tsx index 13152ea9..4a79a967 100644 --- a/pages/auth/login.tsx +++ b/pages/auth/login.tsx @@ -1,6 +1,7 @@ import { HeadSeo } from "@components/seo/head-seo"; import Link from "next/link"; -import { getCsrfToken, getSession } from "next-auth/client"; +import { getCsrfToken } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default function Login({ csrfToken }) { return ( diff --git a/pages/availability/index.tsx b/pages/availability/index.tsx index bf6a8a36..f88c41ae 100644 --- a/pages/availability/index.tsx +++ b/pages/availability/index.tsx @@ -4,9 +4,10 @@ import Modal from "@components/Modal"; import Shell from "@components/Shell"; import { useRouter } from "next/router"; import { useRef, useState } from "react"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import { ClockIcon } from "@heroicons/react/outline"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Availability(props) { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/pages/availability/troubleshoot.tsx b/pages/availability/troubleshoot.tsx index 37f4ad37..0d215d77 100644 --- a/pages/availability/troubleshoot.tsx +++ b/pages/availability/troubleshoot.tsx @@ -3,7 +3,7 @@ import prisma from "@lib/prisma"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import { GetServerSideProps } from "next"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import { useEffect, useState } from "react"; import Shell from "@components/Shell"; diff --git a/pages/bookings/index.tsx b/pages/bookings/index.tsx index 3155b5c3..282e8de0 100644 --- a/pages/bookings/index.tsx +++ b/pages/bookings/index.tsx @@ -1,5 +1,5 @@ import prisma from "@lib/prisma"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import Shell from "@components/Shell"; import { useRouter } from "next/router"; import dayjs from "dayjs"; @@ -9,6 +9,7 @@ import { DotsHorizontalIcon } from "@heroicons/react/solid"; import classNames from "@lib/classNames"; import { ClockIcon, XIcon } from "@heroicons/react/outline"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Bookings({ bookings }) { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/pages/event-types/[type].tsx b/pages/event-types/[type].tsx index be55cac2..e395eba2 100644 --- a/pages/event-types/[type].tsx +++ b/pages/event-types/[type].tsx @@ -7,7 +7,7 @@ import prisma from "@lib/prisma"; import { EventTypeCustomInput, EventTypeCustomInputType } from "@prisma/client"; import { LocationType } from "@lib/location"; import Shell from "@components/Shell"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import { Scheduler } from "@components/ui/Scheduler"; import { Disclosure, RadioGroup } from "@headlessui/react"; import { PhoneIcon, XIcon } from "@heroicons/react/outline"; diff --git a/pages/event-types/index.tsx b/pages/event-types/index.tsx index a6964dc5..b133947f 100644 --- a/pages/event-types/index.tsx +++ b/pages/event-types/index.tsx @@ -15,7 +15,7 @@ import { import classNames from "@lib/classNames"; import showToast from "@lib/notification"; import dayjs from "dayjs"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import Link from "next/link"; import { useRouter } from "next/router"; import React, { Fragment, useRef } from "react"; @@ -25,6 +25,7 @@ import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next"; import { useMutation } from "react-query"; import createEventType from "@lib/mutations/event-types/create-event-type"; import { ONBOARDING_INTRODUCED_AT } from "@lib/getting-started"; +import { getSession } from "@lib/auth"; const EventTypesPage = (props: InferGetServerSidePropsType) => { const { user, types } = props; diff --git a/pages/integrations/[integration].tsx b/pages/integrations/[integration].tsx index 9f2586cd..b53de9e5 100644 --- a/pages/integrations/[integration].tsx +++ b/pages/integrations/[integration].tsx @@ -3,8 +3,9 @@ import { getIntegrationName, getIntegrationType } from "@lib/integrations"; import Shell from "@components/Shell"; import { useState } from "react"; import { useRouter } from "next/router"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Integration(props) { const router = useRouter(); diff --git a/pages/integrations/index.tsx b/pages/integrations/index.tsx index 258b9c5a..970bdf9a 100644 --- a/pages/integrations/index.tsx +++ b/pages/integrations/index.tsx @@ -2,7 +2,7 @@ import Link from "next/link"; import prisma from "@lib/prisma"; import Shell from "@components/Shell"; import { useEffect, useState, useRef, useCallback } from "react"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import { CheckCircleIcon, ChevronRightIcon, PlusIcon, XCircleIcon } from "@heroicons/react/solid"; import { InformationCircleIcon } from "@heroicons/react/outline"; import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTrigger } from "@components/Dialog"; @@ -11,6 +11,7 @@ import Loader from "@components/Loader"; import AddCalDavIntegration, { ADD_CALDAV_INTEGRATION_FORM_TITLE, } from "@lib/integrations/CalDav/components/AddCalDavIntegration"; +import { getSession } from "@lib/auth"; export type Integration = { installed: boolean; diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx index 63b574a4..93048733 100644 --- a/pages/settings/billing.tsx +++ b/pages/settings/billing.tsx @@ -1,7 +1,7 @@ import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; import prisma from "@lib/prisma"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; export default function Billing() { return ( diff --git a/pages/settings/embed.tsx b/pages/settings/embed.tsx index ae2b64b0..6dfc541e 100644 --- a/pages/settings/embed.tsx +++ b/pages/settings/embed.tsx @@ -1,8 +1,9 @@ import prisma from "@lib/prisma"; import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Embed(props) { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/pages/settings/password.tsx b/pages/settings/password.tsx index 23308bcf..b681a473 100644 --- a/pages/settings/password.tsx +++ b/pages/settings/password.tsx @@ -3,8 +3,9 @@ import prisma from "@lib/prisma"; import Modal from "@components/Modal"; import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Settings() { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index 1e67075f..78f0e241 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -5,7 +5,7 @@ import Modal from "@components/Modal"; import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; import Avatar from "@components/Avatar"; -import { getSession } from "next-auth/client"; +import { getSession } from "@lib/auth"; import Select from "react-select"; import TimezoneSelect from "react-timezone-select"; import { UsernameInput } from "@components/ui/UsernameInput"; diff --git a/pages/settings/teams.tsx b/pages/settings/teams.tsx index 837041ec..ce807e7a 100644 --- a/pages/settings/teams.tsx +++ b/pages/settings/teams.tsx @@ -3,11 +3,12 @@ import Shell from "@components/Shell"; import SettingsShell from "@components/Settings"; import { useEffect, useState } from "react"; import type { Session } from "next-auth"; -import { getSession, useSession } from "next-auth/client"; +import { useSession } from "next-auth/client"; import { UsersIcon } from "@heroicons/react/outline"; import TeamList from "@components/team/TeamList"; import TeamListItem from "@components/team/TeamListItem"; import Loader from "@components/Loader"; +import { getSession } from "@lib/auth"; export default function Teams() { const [, loading] = useSession();