From 6eabaaaa591ca212bfe4b65785a54ba947e9f2dc Mon Sep 17 00:00:00 2001 From: Ryan Yocum Date: Sun, 27 Oct 2024 13:02:04 -0400 Subject: [PATCH 1/2] Fixed nextauth typeerror and removed some unused imports. Build works now --- next/app/api/auth/[...nextauth]/route.ts | 24 +++--------------------- next/app/go/GoLink.tsx | 1 - next/app/go/MakeNewGoLink.tsx | 1 - next/app/layout.tsx | 2 +- next/lib/authOptions.ts | 21 +++++++++++++++++++++ next/package-lock.json | 11 +++++++++++ next/package.json | 1 + 7 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 next/lib/authOptions.ts diff --git a/next/app/api/auth/[...nextauth]/route.ts b/next/app/api/auth/[...nextauth]/route.ts index 73094a21..8e1d602f 100644 --- a/next/app/api/auth/[...nextauth]/route.ts +++ b/next/app/api/auth/[...nextauth]/route.ts @@ -1,25 +1,7 @@ -import { PrismaAdapter } from "@auth/prisma-adapter"; -import { PrismaClient } from "@prisma/client"; -import NextAuth, { AuthOptions } from "next-auth"; -import GoogleProvider from "next-auth/providers/google"; +import { authOptions } from "@/lib/authOptions"; +import NextAuth from "next-auth"; -const prisma = new PrismaClient(); -export const authOptions: AuthOptions = { - adapter: PrismaAdapter(prisma), - providers: [ - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID || "", - clientSecret: process.env.GOOGLE_CLIENT_SECRET || "", - authorization: { - params: { - hd: "g.rit.edu", // restrict logins to rit.edu accounts - }, - }, - }), - ], -}; - -export const handler = NextAuth(authOptions); +const handler = NextAuth(authOptions); export { handler as GET, handler as POST }; diff --git a/next/app/go/GoLink.tsx b/next/app/go/GoLink.tsx index 1e744c9d..5f31ca2a 100644 --- a/next/app/go/GoLink.tsx +++ b/next/app/go/GoLink.tsx @@ -3,7 +3,6 @@ import { GoLinkStar } from "@/components/common/Icons"; import { GoLinkEdit } from "@/components/common/Icons"; import { GoLinkDelete } from "@/components/common/Icons"; import { fetchAuthLevel, goLinksApi } from "@/lib/api"; -import { useEffectAsync } from "@/lib/utils"; import { useSession } from "next-auth/react"; import { useCallback, useEffect, useState } from "react"; diff --git a/next/app/go/MakeNewGoLink.tsx b/next/app/go/MakeNewGoLink.tsx index eeceb95c..4136e947 100644 --- a/next/app/go/MakeNewGoLink.tsx +++ b/next/app/go/MakeNewGoLink.tsx @@ -1,7 +1,6 @@ import { useSession } from "next-auth/react"; import { use, useCallback, useEffect, useState } from "react"; import { CreateGoLinkProps } from "./page"; -import { useEffectAsync } from "@/lib/utils"; import { goLinksApi, fetchAuthLevel } from "@/lib/api"; export const GoLinkButton: React.FC = ({ fetchData }) => { diff --git a/next/app/layout.tsx b/next/app/layout.tsx index ecdb4db8..537d6e82 100644 --- a/next/app/layout.tsx +++ b/next/app/layout.tsx @@ -7,7 +7,7 @@ import Footer from "@/components/Footer"; import { Inter } from 'next/font/google' import { Providers } from "./Providers"; import { getServerSession } from "next-auth"; -import { authOptions } from "./api/auth/[...nextauth]/route"; +import { authOptions } from '@/lib/authOptions'; import ScrollToTopButton from "@/components/nav/ScrollToTopButton"; diff --git a/next/lib/authOptions.ts b/next/lib/authOptions.ts new file mode 100644 index 00000000..78514bb9 --- /dev/null +++ b/next/lib/authOptions.ts @@ -0,0 +1,21 @@ +import { PrismaAdapter } from '@next-auth/prisma-adapter'; +import { PrismaClient } from '@prisma/client'; +import { AuthOptions } from 'next-auth'; +import GoogleProvider from 'next-auth/providers/google'; + +const prisma = new PrismaClient(); + +export const authOptions: AuthOptions = { + adapter: PrismaAdapter(prisma), + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID || '', + clientSecret: process.env.GOOGLE_CLIENT_SECRET || '', + authorization: { + params: { + hd: 'g.rit.edu', // restrict logins to rit.edu accounts + }, + }, + }), + ], +}; diff --git a/next/package-lock.json b/next/package-lock.json index c643b84e..072be22f 100644 --- a/next/package-lock.json +++ b/next/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "@auth/prisma-adapter": "^1.0.6", + "@next-auth/prisma-adapter": "^1.0.7", "@prisma/client": "^5.4.2", "@types/react": "18.2.21", "@types/react-dom": "18.2.7", @@ -1543,6 +1544,16 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@next-auth/prisma-adapter": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@next-auth/prisma-adapter/-/prisma-adapter-1.0.7.tgz", + "integrity": "sha512-Cdko4KfcmKjsyHFrWwZ//lfLUbcLqlyFqjd/nYE2m3aZ7tjMNUjpks47iw7NTCnXf+5UWz5Ypyt1dSs1EP5QJw==", + "license": "ISC", + "peerDependencies": { + "@prisma/client": ">=2.26.0 || >=3", + "next-auth": "^4" + } + }, "node_modules/@next/env": { "version": "14.2.8", "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.8.tgz", diff --git a/next/package.json b/next/package.json index 645c4a11..b9237ff8 100644 --- a/next/package.json +++ b/next/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@auth/prisma-adapter": "^1.0.6", + "@next-auth/prisma-adapter": "^1.0.7", "@prisma/client": "^5.4.2", "@types/react": "18.2.21", "@types/react-dom": "18.2.7", From 02fcc661d5570b62d40ad789ef35faa4e38032fc Mon Sep 17 00:00:00 2001 From: Ryan Yocum Date: Sun, 27 Oct 2024 13:03:48 -0400 Subject: [PATCH 2/2] Fixed formatting --- next/lib/authOptions.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/next/lib/authOptions.ts b/next/lib/authOptions.ts index 78514bb9..30431701 100644 --- a/next/lib/authOptions.ts +++ b/next/lib/authOptions.ts @@ -1,21 +1,21 @@ -import { PrismaAdapter } from '@next-auth/prisma-adapter'; -import { PrismaClient } from '@prisma/client'; -import { AuthOptions } from 'next-auth'; -import GoogleProvider from 'next-auth/providers/google'; +import { PrismaAdapter } from "@next-auth/prisma-adapter"; +import { PrismaClient } from "@prisma/client"; +import { AuthOptions } from "next-auth"; +import GoogleProvider from "next-auth/providers/google"; const prisma = new PrismaClient(); export const authOptions: AuthOptions = { - adapter: PrismaAdapter(prisma), - providers: [ - GoogleProvider({ - clientId: process.env.GOOGLE_CLIENT_ID || '', - clientSecret: process.env.GOOGLE_CLIENT_SECRET || '', - authorization: { - params: { - hd: 'g.rit.edu', // restrict logins to rit.edu accounts - }, - }, - }), - ], + adapter: PrismaAdapter(prisma), + providers: [ + GoogleProvider({ + clientId: process.env.GOOGLE_CLIENT_ID || "", + clientSecret: process.env.GOOGLE_CLIENT_SECRET || "", + authorization: { + params: { + hd: "g.rit.edu", // restrict logins to rit.edu accounts + }, + }, + }), + ], };