From b20fadd33fe4d2956a43adb38ec59a11bee47a09 Mon Sep 17 00:00:00 2001 From: Joywin Bennis <107112207+joywin2003@users.noreply.github.com> Date: Wed, 11 Sep 2024 23:08:46 +0530 Subject: [PATCH] Refactor: moved the auth options and version to fix build errors - by vyshnav --- package-lock.json | 2 ++ src/app/api/auth/[...nextauth]/route.ts | 8 ++------ .../auth/[...nextauth]/options.ts => lib/auth-options.ts} | 6 +++--- src/lib/get-server-session.ts | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) rename src/{app/api/auth/[...nextauth]/options.ts => lib/auth-options.ts} (89%) diff --git a/package-lock.json b/package-lock.json index 0cbb056..2b3d322 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1444,6 +1444,7 @@ "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" @@ -1670,6 +1671,7 @@ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.19.1.tgz", "integrity": "sha512-x30GFguInsgt+4z5I4WbkZP2CGpotJMUXy+Gl/aaUjHn2o1DnLYNTA+q9XdYmAQZM8fIIkvUiA2NpgosM3fneg==", "hasInstallScript": true, + "license": "Apache-2.0", "engines": { "node": ">=16.13" }, diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 639cea6..b32de7d 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,7 +1,3 @@ -import { authOptions } from "./options"; +import { handlers } from "@/lib/auth-options"; -import NextAuth from "next-auth"; - -export const handlers = NextAuth(authOptions); - -export { handlers as GET, handlers as POST }; +export { handlers as GET, handlers as POST }; \ No newline at end of file diff --git a/src/app/api/auth/[...nextauth]/options.ts b/src/lib/auth-options.ts similarity index 89% rename from src/app/api/auth/[...nextauth]/options.ts rename to src/lib/auth-options.ts index 621191d..913bafd 100644 --- a/src/app/api/auth/[...nextauth]/options.ts +++ b/src/lib/auth-options.ts @@ -1,11 +1,11 @@ -import NextAuth, { DefaultSession, type NextAuthOptions, type Session as NextAuthSession } from "next-auth"; +import { DefaultSession, type NextAuthOptions, type Session as NextAuthSession } from "next-auth"; +import NextAuth from "next-auth/next"; import GoogleProvider from "next-auth/providers/google"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import prisma from "@/server/db"; import { UserRoleType } from "@/types"; import { JWT } from "next-auth/jwt"; - declare module "next-auth" { interface Session { user: { @@ -58,4 +58,4 @@ export const authOptions: NextAuthOptions = { // debug: process.env.NODE_ENV === "development", }; -export default NextAuth(authOptions); +export const handlers = NextAuth(authOptions); diff --git a/src/lib/get-server-session.ts b/src/lib/get-server-session.ts index e2cd473..b9f7ff7 100644 --- a/src/lib/get-server-session.ts +++ b/src/lib/get-server-session.ts @@ -1,6 +1,6 @@ import { getServerSession } from "next-auth"; -import { authOptions } from "@/app/api/auth/[...nextauth]/options"; +import { authOptions } from "@/lib/auth-options"; export async function getServerSideSession() { - return await getServerSession(authOptions); + return await getServerSession(authOptions); }