From 348c4cf9496cc241febd12686452d9926b456754 Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Mon, 1 Sep 2025 06:55:40 +0000 Subject: [PATCH] I see this error with the app, reported by NextJS, please fix it. The er --- local.db-shm | Bin 0 -> 32768 bytes local.db-wal | Bin 0 -> 37112 bytes src/auth.config.ts | 32 ++------------------------------ src/auth.ts | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 31 deletions(-) create mode 100644 local.db-shm create mode 100644 local.db-wal diff --git a/local.db-shm b/local.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..24256b589d56510e676b2818d7ab3b04cf311458 GIT binary patch literal 32768 zcmeI*F-`(O6b9e{5dlS@BjF63fRfrn*qL~Sy$3hoBsO$Z^jJYjVF3laAsb_2Maz7D z@-manW_JJY0yExDQ_e$7Bc)+C)C|00TY;(m4Dsi9}go-$U=mGV@ArciTLSlaGI^KBWLQ16m_^#xg znYTMLZ$2~oL*w^mkG~V#@E!g2ai8xoAKz}?(N>V%PONy(HIQqH`bSBN7e6A{9;HZ@u~os^YV%cMBRewBPaEsj{1 zn}(OX*=nqry3rbREF)F$F1TeZw+wn-wHhl%U6dj#WSSY2_KA&4O_QCkvbWn@v8>E0 zC0jq9UF~Wqg|ynRwU%j9?<{=AyZl;XOu-U;WRQ$oLIL> zDS7(LTuI5z7Uk)ZVv3ZM8KtBYv&w=1OUZ<(r^sB9Oe=YXbwM_>kj+dhjBo0NNHCcl z_xsGcZd{@lYV0Lm)!J4=q*bSv)JZ26-53golF6ihvnqOdxz@Ny#cssazd~epuBki7 zNN?*hmGWG!$Z{2wqTTqqw(8m0x6G{t1W{u)iV~EW&^IAD=4ht zGnq=hOtO^{15;MHaG{(j%u9;xrv9&UaB7`XApv2dA|SBAu2ZoKyC4YB{|3QW)y&$x zwpVCB5)37e9PxK@LVHoJY8k7|8iPQ0B}1+j?K(KHZ4xbQFTG(@t)6aMYUr0mlIx-k zi+e`ruuz2>mSxsor%rgtRk-2-KU00@8p2!H?xfB*=900@8p z2!OzSM}SWO#GHA7t3S=2c>0fbKZPH`eb-M=2n0X?1V8`;KmY_l00ck)1V8`;4uXKo zk0AcbHy>@0XO7*)k08;b2w%T&-+lz~(2YI)2tqf)pY_y(C8bV{*M za%#%IaYoq6uNf_K*{o`OU2wU;I`t66T^95nCv;a_HtH5D&wEYzon_*?HuiF{>A}|X zy$hbRRoI;x(nOS(;;Sty@nCXsYOmFnJ@i#4J%kDP5wKA};YWb)5#W0S_#T1%jgEdd zDEJXPDt-iU{)*w)3l#30ycX5hzlI;dzFxeL2?Rg@1V8`;KmY_l00ck)1V8`;9y9{{ wzyE|YFK})B$MwSY?Njh0c+k2L`hoxmfB*=900@8p2!H?xfB*=9z<($34=t?GfdBvi literal 0 HcmV?d00001 diff --git a/src/auth.config.ts b/src/auth.config.ts index 55037cd..787e97e 100644 --- a/src/auth.config.ts +++ b/src/auth.config.ts @@ -9,36 +9,8 @@ export const authConfig = { signIn: '/login', }, providers: [ - Credentials({ - async authorize(credentials) { - const parsedCredentials = z - .object({ email: z.string().email(), password: z.string().min(1) }) - .safeParse(credentials); - - if (parsedCredentials.success) { - const { email, password } = parsedCredentials.data; - - try { - const userStmt = db.prepare('SELECT * FROM users WHERE email = ?'); - const user = userStmt.get(email) as any; - - if (!user) return null; - - // WARNING: Storing passwords in plaintext is insecure. - // This is for demonstration purposes only. - // In a real application, you MUST hash and salt passwords. - const passwordsMatch = password === user.password; - - if (passwordsMatch) return user; - } catch (e) { - console.error(e) - return null - } - } - - return null; - }, - }), + // The Credentials provider logic has been moved to src/auth.ts + // to prevent the database module from being bundled with middleware. ], callbacks: { authorized({ auth, request: { nextUrl } }) { diff --git a/src/auth.ts b/src/auth.ts index caf447f..bfa7472 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,7 +1,44 @@ import NextAuth from 'next-auth'; import { authConfig } from './auth.config'; +import Credentials from 'next-auth/providers/credentials'; +import { z } from 'zod'; +import db from '@/lib/db'; -export const { handlers, auth, signIn, signOut } = NextAuth(authConfig); +export const { handlers, auth, signIn, signOut } = NextAuth({ + ...authConfig, + providers: [ + Credentials({ + async authorize(credentials) { + const parsedCredentials = z + .object({ email: z.string().email(), password: z.string().min(1) }) + .safeParse(credentials); + + if (parsedCredentials.success) { + const { email, password } = parsedCredentials.data; + + try { + const userStmt = db.prepare('SELECT * FROM users WHERE email = ?'); + const user = userStmt.get(email) as any; + + if (!user) return null; + + // WARNING: Storing passwords in plaintext is insecure. + // This is for demonstration purposes only. + // In a real application, you MUST hash and salt passwords. + const passwordsMatch = password === user.password; + + if (passwordsMatch) return user; + } catch (e) { + console.error(e) + return null + } + } + + return null; + }, + }), + ] +}); export const runtime = "nodejs";