diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..59650cb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "prettier.jsxSingleQuote": true, + "prettier.singleQuote": true, + "prettier.trailingComma": "none" +} diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index fae4907..0aa1cd7 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1 +1,2 @@ -export { GET, POST } from '@/auth'; +import { handlers } from '@/auth'; +export const { GET, POST } = handlers; diff --git a/auth.ts b/auth.ts index bc07833..fa7ac22 100644 --- a/auth.ts +++ b/auth.ts @@ -5,13 +5,7 @@ import prismadb from '@/lib/prismadb'; import authConfig from '@/auth.config'; import { getUserById } from '@/data/user'; -export const { - handlers: { GET, POST }, - auth, - signIn, - signOut, - update -} = NextAuth({ +export const { handlers, auth, signIn, signOut, unstable_update } = NextAuth({ pages: { signIn: '/auth/sign-in', error: '/auth/sign-in' @@ -24,7 +18,7 @@ export const { if (session.user) { session.user.name = token.name; - session.user.email = token.email; + session.user.email = token.email as string; } return session; @@ -46,9 +40,9 @@ export const { return token; } }, - adapter: PrismaAdapter(prismadb), - debug: process.env.NODE_ENV !== 'production', - secret: process.env.AUTH_SECRET, + ...authConfig, session: { strategy: 'jwt' }, - ...authConfig + secret: process.env.AUTH_SECRET, + adapter: PrismaAdapter(prismadb), + debug: process.env.NODE_ENV !== 'production' }); diff --git a/middleware.ts b/middleware.ts index 28fdb5c..db7ccc3 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,6 +1,4 @@ -import NextAuth from 'next-auth'; - -import authConfig from '@/auth.config'; +import { auth } from '@/auth'; import { authRoutes, publicRoutes, @@ -8,8 +6,6 @@ import { DEFAULT_SIGNIN_REDIRECT } from '@/routes'; -export const { auth } = NextAuth(authConfig); - export default auth((req) => { const { nextUrl } = req; const isSignedIn = !!req.auth; @@ -19,15 +15,17 @@ export default auth((req) => { const isAuthRoute = authRoutes.includes(nextUrl.pathname); if (isApiAuthRoute || isPublicRoute) { - return null; + return; } if (isAuthRoute) { if (isSignedIn) { - return Response.redirect(new URL(DEFAULT_SIGNIN_REDIRECT, nextUrl)); + return Response.redirect( + new URL(DEFAULT_SIGNIN_REDIRECT, nextUrl).toString() + ); } - return null; + return; } if (!isSignedIn && !isPublicRoute) { @@ -39,11 +37,14 @@ export default auth((req) => { const encodedCallbackUrl = encodeURIComponent(callbackUrl); return Response.redirect( - new URL(`/auth/sign-in?callbackUrl=${encodedCallbackUrl}`, nextUrl) + new URL( + `/auth/sign-in?callbackUrl=${encodedCallbackUrl}`, + nextUrl + ).toString() ); } - return null; + return; }); export const config = { diff --git a/package.json b/package.json index 17e12b9..f7593fe 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "framer-motion": "^11.1.7", "lucide-react": "^0.321.0", "next": "^14.2.3", - "next-auth": "5.0.0-beta.4", + "next-auth": "5.0.0-beta.17", "next-themes": "^0.3.0", "plaiceholder": "^3.0.0", "react": "^18.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e176f20..fd1c64b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -102,8 +102,8 @@ importers: specifier: ^14.2.3 version: 14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1) next-auth: - specifier: 5.0.0-beta.4 - version: 5.0.0-beta.4(next@14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1) + specifier: 5.0.0-beta.17 + version: 5.0.0-beta.17(next@14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1) next-themes: specifier: ^0.3.0 version: 0.3.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -199,14 +199,6 @@ packages: resolution: {integrity: sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==} engines: {node: '>=10'} - '@auth/core@0.18.4': - resolution: {integrity: sha512-GsNhsP1xE/3FoNS3dVkPjqRljLNJ4iyL2OLv3klQGNvw3bMpROFcK4lqhx7+pPHiamnVaYt2vg1xbB+lsNaevg==} - peerDependencies: - nodemailer: ^6.8.0 - peerDependenciesMeta: - nodemailer: - optional: true - '@auth/core@0.30.0': resolution: {integrity: sha512-8AE4m/nk+4EIiVCJwxZAsJeAQuzpEC8M8768mmKVn60CGDdupKQkVhxbRlm5Qh7eNRCoFFME+0DvtaX2aXrYaA==} peerDependencies: @@ -3337,13 +3329,19 @@ packages: neo-async@2.6.2: resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==} - next-auth@5.0.0-beta.4: - resolution: {integrity: sha512-vgocjvwPA8gxd/zrIP/vr9lJ/HeNe+C56lPP1D3sdyenHt8KncQV6ro7q0xCsDp1fcOKx7WAWVZH5o8aMxDzgw==} + next-auth@5.0.0-beta.17: + resolution: {integrity: sha512-XA/7JtAjOgDfAeotJPFUsFZGGItZwzZrxLt9Gc9fE7EchLk6zydZfuZ22Vvwixs3IilkN644D5IoD5tEOAFGCQ==} peerDependencies: + '@simplewebauthn/browser': ^9.0.1 + '@simplewebauthn/server': ^9.0.2 next: ^14 nodemailer: ^6.6.5 react: ^18.2.0 peerDependenciesMeta: + '@simplewebauthn/browser': + optional: true + '@simplewebauthn/server': + optional: true nodemailer: optional: true @@ -4249,15 +4247,6 @@ snapshots: '@alloc/quick-lru@5.2.0': {} - '@auth/core@0.18.4': - dependencies: - '@panva/hkdf': 1.1.1 - cookie: 0.6.0 - jose: 5.2.4 - oauth4webapi: 2.10.4 - preact: 10.11.3 - preact-render-to-string: 5.2.3(preact@10.11.3) - '@auth/core@0.30.0': dependencies: '@panva/hkdf': 1.1.1 @@ -7995,9 +7984,9 @@ snapshots: neo-async@2.6.2: {} - next-auth@5.0.0-beta.4(next@14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1): + next-auth@5.0.0-beta.17(next@14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react@18.3.1): dependencies: - '@auth/core': 0.18.4 + '@auth/core': 0.30.0 next: 14.2.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: 18.3.1