From 51ef3ae719f98f55f631a6cc8894cb850a32bd89 Mon Sep 17 00:00:00 2001 From: Niall Maher Date: Tue, 15 Aug 2023 15:59:15 +0100 Subject: [PATCH] Update Node, update severSession function (#384) --- components/PromptService/PromptService.tsx | 2 +- package.json | 4 +- pages/[username].tsx | 8 +- pages/alpha/create-new/[[...postIdArr]].tsx | 8 +- pages/alpha/create/[[...postIdArr]].tsx | 10 +- pages/create/[[...postIdArr]].tsx | 8 +- pages/metrics/index.tsx | 8 +- pages/my-posts/index.tsx | 409 ++++++++++---------- pages/notifications/index.tsx | 8 +- pages/saved/index.tsx | 8 +- pages/settings/index.tsx | 8 +- server/common/get-server-auth-session.ts | 6 +- server/trpc/context.ts | 2 +- 13 files changed, 232 insertions(+), 257 deletions(-) diff --git a/components/PromptService/PromptService.tsx b/components/PromptService/PromptService.tsx index 60a84495..cfab92b7 100644 --- a/components/PromptService/PromptService.tsx +++ b/components/PromptService/PromptService.tsx @@ -1,7 +1,7 @@ import { useRouter } from "next/router"; import React, { useState, useEffect, useCallback } from "react"; import { Modal } from "../Modal/Modal"; -import { ExclamationIcon, PlusSmIcon, XIcon } from "@heroicons/react/outline"; +import { ExclamationIcon, XIcon } from "@heroicons/react/outline"; import { Dialog } from "@headlessui/react"; export interface serviceProps { diff --git a/package.json b/package.json index 12a67afe..2a928bf2 100644 --- a/package.json +++ b/package.json @@ -90,8 +90,8 @@ "typescript": "^4.6.4" }, "volta": { - "node": "16.19.0", - "npm": "8.19.3" + "node": "18.17.1", + "npm": "9.6.7" }, "overrides": { "json5@<1.0.2": "1.0.2", diff --git a/pages/[username].tsx b/pages/[username].tsx index dfe82bfa..cfced51e 100644 --- a/pages/[username].tsx +++ b/pages/[username].tsx @@ -5,7 +5,7 @@ import type { } from "next"; import React from "react"; import Link from "next/link"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth/next"; import { authOptions } from "./api/auth/[...nextauth]"; import prisma from "../server/db/client"; import Layout from "../components/Layout/Layout"; @@ -210,11 +210,7 @@ export const getServerSideProps = async ( }; } - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); const profile = await prisma.user.findUnique({ where: { diff --git a/pages/alpha/create-new/[[...postIdArr]].tsx b/pages/alpha/create-new/[[...postIdArr]].tsx index 4616ba3c..a9ed357a 100644 --- a/pages/alpha/create-new/[[...postIdArr]].tsx +++ b/pages/alpha/create-new/[[...postIdArr]].tsx @@ -2,7 +2,7 @@ import type { NextPage, GetServerSideProps } from "next"; import { ZodError } from "zod"; import { useRouter } from "next/router"; import React, { useState, useEffect, Fragment, useRef } from "react"; -import { unstable_getServerSession } from "next-auth/next"; +import { getServerSession } from "next-auth/next"; import { authOptions } from "../../api/auth/[...nextauth]"; import { useForm, Controller } from "react-hook-form"; import toast, { Toaster } from "react-hot-toast"; @@ -614,11 +614,7 @@ const Create: NextPage = () => { }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/alpha/create/[[...postIdArr]].tsx b/pages/alpha/create/[[...postIdArr]].tsx index 95366472..c8840565 100644 --- a/pages/alpha/create/[[...postIdArr]].tsx +++ b/pages/alpha/create/[[...postIdArr]].tsx @@ -3,7 +3,7 @@ import type { NextPage, GetServerSideProps } from "next"; import { ZodError } from "zod"; import { useRouter } from "next/router"; import React, { useState, useEffect, Fragment, useRef } from "react"; -import { unstable_getServerSession } from "next-auth/next"; +import { getServerSession } from "next-auth/next"; import { authOptions } from "../../api/auth/[...nextauth]"; import { useForm } from "react-hook-form"; import CustomTextareaAutosize from "../../../components/CustomTextareAutosize/CustomTextareaAutosize"; @@ -265,6 +265,8 @@ const Create: NextPage = () => {
@@ -559,11 +561,7 @@ const Create: NextPage = () => { }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/create/[[...postIdArr]].tsx b/pages/create/[[...postIdArr]].tsx index 1a6fd15f..0c1ee85a 100644 --- a/pages/create/[[...postIdArr]].tsx +++ b/pages/create/[[...postIdArr]].tsx @@ -2,7 +2,7 @@ import type { NextPage, GetServerSideProps } from "next"; import { ZodError } from "zod"; import { useRouter } from "next/router"; import React, { useState, useEffect, Fragment, useRef } from "react"; -import { unstable_getServerSession } from "next-auth/next"; +import { getServerSession } from "next-auth/next"; import { authOptions } from "../api/auth/[...nextauth]"; import { useForm } from "react-hook-form"; import CustomTextareaAutosize from "../../components/CustomTextareAutosize/CustomTextareaAutosize"; @@ -615,11 +615,7 @@ const Create: NextPage = () => { }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/metrics/index.tsx b/pages/metrics/index.tsx index c69bff3a..a49778a0 100644 --- a/pages/metrics/index.tsx +++ b/pages/metrics/index.tsx @@ -1,7 +1,7 @@ import Layout from "../../components/Layout/Layout"; import PageHeading from "../../components/PageHeading/PageHeading"; import { authOptions } from "../api/auth/[...nextauth]"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth"; import type { GetServerSideProps, InferGetServerSidePropsType, @@ -55,11 +55,7 @@ const Metrics: NextPage = ({ }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session || !session?.user?.id) { return { diff --git a/pages/my-posts/index.tsx b/pages/my-posts/index.tsx index dad59cf3..52654c14 100644 --- a/pages/my-posts/index.tsx +++ b/pages/my-posts/index.tsx @@ -7,7 +7,7 @@ import type { import { useRouter } from "next/router"; import { ExclamationIcon, XIcon } from "@heroicons/react/outline"; import { Dialog, Transition, Menu } from "@headlessui/react"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth"; import Link from "next/link"; import { ChevronDownIcon, @@ -67,214 +67,223 @@ const MyPosts: NextPage = ({ return ( - setSelectedArticleToDelete(undefined)} - > -
- -
-
-
-
-
- + setSelectedArticleToDelete(undefined)} + > +
+ +
+
+
+
+
+ + Delete article + +
+

+ Are you sure you want to delete this article? +

+

+ All of the data will be permanently removed from our servers + forever. This action cannot be undone. +

+
-
-
- - -
- -
-
-
- - {/* Use an "onChange" listener to redirect the user to the selected tab URL. */} - + {deleteStatus === "loading" ? "Deleting..." : "Delete"} + +
-
- + +
+
+
+ + {/* Use an "onChange" listener to redirect the user to the selected tab URL. */} + +
+
+ +
-
- -
- {selectedTabData.status === "loading" && ( -

Fetching your posts...

- )} - {selectedTabData.status === "error" && ( -

- Something went wrong fetching your posts... Refresh the page. -

- )} - {selectedTabData.status === "success" && - selectedTabData.data?.map( - ({ id, title, excerpt, readTimeMins, slug }) => ( -
- {tab === "published" ? ( - -

- {title} -

- - ) : ( -

{title}

- )} -

{excerpt || "No excerpt yet... Write more to see one."}

-

- Read time so far: {readTimeMins} mins -

-
- -
- - Options - -
+
+ {selectedTabData.status === "loading" && ( +

Fetching your posts...

+ )} + {selectedTabData.status === "error" && ( +

+ Something went wrong fetching your posts... Refresh the page. +

+ )} - ( +
+ {tab === "published" ? ( + +

+ {title} +

+ + ) : ( +

{title}

+ )} +

+ {excerpt || "No excerpt yet... Write more to see one."} +

+

+ Read time so far: {readTimeMins} mins +

+
+ - -
- - {({ active }) => ( - - +
+ + Options + +
- - {({ active }) => ( - - )} - -
-
- -
-
-
- ) - )} - {selectedTabData.status === "success" && - selectedTabData.data?.length === 0 && ( -

Nothing to show here... 🥲

- )} + + +
+ + {({ active }) => ( + + + + + {({ active }) => ( + + )} + +
+
+
+
+
+
+ ) + )} + {selectedTabData.status === "success" && + selectedTabData.data?.length === 0 && ( +

Nothing to show here... 🥲

+ )} +
-
+ ); }; @@ -282,11 +291,7 @@ const MyPosts: NextPage = ({ export default MyPosts; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/notifications/index.tsx b/pages/notifications/index.tsx index 388f3d4c..c26a1f06 100644 --- a/pages/notifications/index.tsx +++ b/pages/notifications/index.tsx @@ -12,7 +12,7 @@ import Layout from "../../components/Layout/Layout"; import PageHeading from "../../components/PageHeading/PageHeading"; import { trpc } from "../../utils/trpc"; import { authOptions } from "../api/auth/[...nextauth]"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth"; import type { GetServerSideProps } from "next/types"; const Notifications = () => { @@ -230,11 +230,7 @@ const Notifications = () => { }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/saved/index.tsx b/pages/saved/index.tsx index 596cb3d1..409916ca 100644 --- a/pages/saved/index.tsx +++ b/pages/saved/index.tsx @@ -5,7 +5,7 @@ import type { InferGetServerSidePropsType, } from "next"; import { useRouter } from "next/router"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth"; import ArticlePreview from "../../components/ArticlePreview/ArticlePreview"; import Layout from "../../components/Layout/Layout"; import { authOptions } from "../api/auth/[...nextauth]"; @@ -108,11 +108,7 @@ const MyPosts: NextPage = ({ export default MyPosts; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session) { return { diff --git a/pages/settings/index.tsx b/pages/settings/index.tsx index 9e552c25..19ee95a3 100644 --- a/pages/settings/index.tsx +++ b/pages/settings/index.tsx @@ -5,7 +5,7 @@ import type { } from "next"; import { useRouter } from "next/router"; import { customAlphabet } from "nanoid"; -import { unstable_getServerSession } from "next-auth/next"; +import { getServerSession } from "next-auth/next"; import { authOptions } from "../api/auth/[...nextauth]"; import { useState } from "react"; import { Switch } from "@headlessui/react"; @@ -444,11 +444,7 @@ const Settings: NextPage = ({ }; export const getServerSideProps: GetServerSideProps = async (context) => { - const session = await unstable_getServerSession( - context.req, - context.res, - authOptions - ); + const session = await getServerSession(context.req, context.res, authOptions); if (!session?.user?.id) { return { diff --git a/server/common/get-server-auth-session.ts b/server/common/get-server-auth-session.ts index b2b90ed9..57bbba70 100644 --- a/server/common/get-server-auth-session.ts +++ b/server/common/get-server-auth-session.ts @@ -1,15 +1,15 @@ import { type GetServerSidePropsContext } from "next"; -import { unstable_getServerSession } from "next-auth"; +import { getServerSession } from "next-auth"; import { authOptions } from "../../pages/api/auth/[...nextauth]"; /** - * Wrapper for unstable_getServerSession https://next-auth.js.org/configuration/nextjs + * Wrapper for getServerSession https://next-auth.js.org/configuration/nextjs * See example usage in trpc createContext or the restricted API route */ export const getServerAuthSession = async (ctx: { req: GetServerSidePropsContext["req"]; res: GetServerSidePropsContext["res"]; }) => { - return await unstable_getServerSession(ctx.req, ctx.res, authOptions); + return await getServerSession(ctx.req, ctx.res, authOptions); }; diff --git a/server/trpc/context.ts b/server/trpc/context.ts index e4e72533..18f0d11d 100644 --- a/server/trpc/context.ts +++ b/server/trpc/context.ts @@ -28,7 +28,7 @@ export const createContextInner = async (opts: CreateContextOptions) => { export const createContext = async (opts: CreateNextContextOptions) => { const { req, res } = opts; - // Get the session from the server using the unstable_getServerSession wrapper function + // Get the session from the server using the getServerSession wrapper function const session = await getServerAuthSession({ req, res }); return await createContextInner({