Closed ansemjo closed 2 years ago
I've used the high art of console.log
-debugging .. and indeed the session
object is somehow undefined
DEBUG session.get() c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc
DEBUG case1: prisma.session.findUnique({ where: { sid: c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc } })
DEBUG case2: session is undefined
app:error TypeError: Cannot read property 'data' of undefined
TypeError: Cannot read property 'data' of undefined
at PrismaSessionStore.<anonymous> (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:305:74)
at step (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:61:23)
at Object.next (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:42:53)
at fulfilled (/path/to/project/node_modules/@quixo3/prisma-session-store/dist/lib/prisma-session-store.js:33:58)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
prisma:query BEGIN; [] 0 ms
prisma:query SELECT "public"."Session"."id", "public"."Session"."sid", "public"."Session"."data", "public"."Session"."expiresAt" FROM "public"."Session" WHERE "public"."Session"."sid" = $1 LIMIT $2 OFFSET $3; ["c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc",1,0] 1 ms
prisma:query ROLLBACK; [] 0 ms
GET 500 /api/login 52b 12.787ms 2021-08-11T13:33:07.384Z
Error:
Invalid `prisma.session.delete()` invocation:
An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
at cb (/path/to/project/node_modules/@prisma/client/runtime/index.js:35943:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Apparently it's Schrödinger's session though. If I add a .then()
after the prisma query, the session object becomes null
:
DEBUG session.get() c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc
DEBUG case1: prisma.session.findUnique({ where: { sid: c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc } })
prisma:query SELECT "public"."Session"."id", "public"."Session"."sid", "public"."Session"."data", "public"."Session"."expiresAt" FROM "public"."Session" WHERE "public"."Session"."sid" = $1 LIMIT $2 OFFSET $3; ["c2BzZpIeQkWayMR-W-4BDgupk0q5uuxc",1,0] 1 ms
DEBUG prisma result: null
DEBUG case2: session is null
GET 403 /api/login 12b 10.606ms 2021-08-11T13:38:22.191Z
Logging in still does not work though because I get a different error later on:
app:auth { id: 1, name: 'Max Mustermann', pkz: null, type: 'local' }
prisma:query BEGIN; [] 0 ms
prisma:query SELECT "public"."Session"."id" FROM "public"."Session" WHERE "public"."Session"."sid" = $1; ["84zxpnfBNyp-f64tQz2EELAQBTRfu9o9"] 1 ms
prisma:query ROLLBACK; [] 0 ms
(node:456710) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.session.update()` invocation:
An operation failed because it depends on one or more records that were required but not found. Record to update not found.
at cb (/path/to/project/node_modules/@prisma/client/runtime/index.js:35943:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
I am a little lost .. is this possibly a prisma issue?
Not sure... Haven't seen anything like this yet.
Internally, prisma-session-store
has been using an older version of Prisma; I've just updated that, and hope the PR will complete this week.
Perhaps this will improve matters?
Aye. I've subscribed to its merging and will try again then. (just for reference: #55 appears to be the PR in question)
👍
I noticed your PR updated prisma to 2.29.1
(I've used 2.29.0
above). Looking at the release notes, there's a link to this issue: https://github.com/prisma/prisma/issues/8718. I'd say this fits my observation of a "Schrödinger's session" above.
And indeed, simply updating to @prisma/client
and prisma
to 2.29.1
fixes this issue for me.
Thus I'm closing this. It appears to have been a prisma issue indeed.
@ansemjo Glad to hear its resolved!
I haven't looked into it very far yet but I've ran
yarn upgrade
earlier today, which updated both@prisma/client
andprisma
from2.28.0
to2.29.0
. Trying to login or really just visiting any site which requires a session now results in the following error:Reverting these two packages to
~2.28.0
fixes the issue again.For reference, my database model and initialization code
```prisma model Session { id String @id sid String @unique data String expiresAt DateTime } ``` ```typescript return Session({ name: SessionCookie, cookie: { maxAge: 7 * 24 * 60 * 60 * 1000, // ms, 7 days sameSite: "strict", secure: "auto", }, secret: key, resave: false, saveUninitialized: false, unset: "destroy", store: new PrismaSessionStore(prisma, { checkPeriod: 10 * 60 * 1000, // ms, 10 minutes dbRecordIdIsSessionId: true, dbRecordIdFunction: undefined, }), }); ```It appears that it is this line that throws: https://github.com/kleydon/prisma-session-store/blob/8941f85564128bfb2cb1238aebe7670ddb1a3c55/src/lib/prisma-session-store.ts#L242
Since it tries to lookup a specific
sid
, I tried to clear cookies but that didn't help. Running the query manually returnsnull
, which should properly return from the function before trying to parse anything?