lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
BSD Zero Clause License
9.6k stars 495 forks source link

[Bug]: TypeError: Cannot destructure property 'id' of 'raw' as it is null. #1701

Open MahirAlam opened 1 month ago

MahirAlam commented 1 month ago

Package

​@lucia-auth/session-drizzle

Describe the bug

It is so sudden!

I checked everything all (everything was working). then, I pushed the code to github and then the production build showed an error (the error started showing in production when I changed the username and name by updating the DB) and when I ran the dev server same Kind of error was showing!

The error!

 ⨯ node_modules\@lucia-auth\adapter-drizzle\dist\drivers\postgresql.js (72:13) @ transformIntoDatabaseUser
 ⨯ TypeError: Cannot destructure property 'id' of 'raw' as it is null.
    at async $$ACTION_0 (./src/libs/auth.ts:60:20)
digest: "1922790224"
  70 | }
  71 | function transformIntoDatabaseUser(raw) {
> 72 |     const { id, ...attributes } = raw;
     |             ^
  73 |     return {
  74 |         id,
  75 |         attributes
 ⨯ node_modules\@lucia-auth\adapter-drizzle\dist\drivers\postgresql.js (72:13) @ transformIntoDatabaseUser
 ⨯ TypeError: Cannot destructure property 'id' of 'raw' as it is null.
    at async $$ACTION_0 (./src/libs/auth.ts:60:20)
digest: "1922790224"
  70 | }
  71 | function transformIntoDatabaseUser(raw) {
> 72 |     const { id, ...attributes } = raw;
     |             ^
  73 |     return {
  74 |         id,
  75 |         attributes

I also sometime get this message

tP [Error]: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options
    at Proxy.callable (E:\tera-tok\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:36:13125)
    at eval (webpack-internal:///(rsc)/./src/libs/auth.ts:62:69)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async AuthLayout (webpack-internal:///(rsc)/./src/app/(auth)/layout.tsx:16:22)
tP [Error]: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options
    at Proxy.callable (E:\tera-tok\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:36:13125)
    at eval (webpack-internal:///(rsc)/./src/libs/auth.ts:62:69)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async AuthLayout (webpack-internal:///(rsc)/./src/app/(auth)/layout.tsx:16:22)
I always ignore it.

I tried deleting the DB and tried loging in again e.t.c. but nothing worked!

ishaba commented 1 week ago

Having the same issue after updating dependecies, trying to figure out which one cause the issue

pilcrowonpaper commented 1 week ago

Sorry for the late response, what drivers are you using? @lucia-auth/adapter-drizzle uses pg for its tests and it's working fine

pilcrowonpaper commented 1 week ago

I'm really confused with this since the error indicates the session is defined but the user isn't. I'm not sure how that's possible with an INNER JOIN.

const result = await this.db
    .select({
        user: this.userTable,
        session: this.sessionTable
    })
    .from(this.sessionTable)
    .innerJoin(this.userTable, eq(this.sessionTable.userId, this.userTable.id))
    .where(eq(this.sessionTable.id, sessionId));