HemmeligOrg / Hemmelig.app

Keep your sensitive information out of chat logs, emails, and more with encrypted secrets.
https://hemmelig.app
MIT License
684 stars 59 forks source link

Prisma error when creating new secret #244

Closed robertripoll closed 7 months ago

robertripoll commented 8 months ago

The server is returning the following error when creating a new secret while I'm logged in (using latest version v5.15.4):

{"level":50,"time":1703876192116,"pid":18,"hostname":"secrets","reqId":"req-28","req":{"method":"POST","url":"/api/secret","hostname":"XXX","remoteAddress":"XXX","remotePort":48242},"res":{"statusCode":500},"err":{"type":"PrismaClientKnownRequestError","message":"\nInvalid prisma.secret.create() invocation:\n\n\nForeign key constraint failed on the field: foreign key","stack":"Error: \nInvalid prisma.secret.create() invocation:\n\n\nForeign key constraint failed on the field: foreign key\n at fn.handleRequestError (/home/node/hemmelig/node_modules/@prisma/client/runtime/library.js:174:6477)\n at fn.handleAndLogRequestError (/home/node/hemmelig/node_modules/@prisma/client/runtime/library.js:174:5907)\n at fn.request (/home/node/hemmelig/node_modules/@prisma/client/runtime/library.js:174:5786)\n at async t._request (/home/node/hemmelig/node_modules/@prisma/client/runtime/library.js:177:10477)\n at async Object. (file:///home/node/hemmelig/src/server/controllers/secret.js:144:28)","code":"P2003","clientVersion":"4.12.0","meta":{"field_name":"foreign key"}},"msg":"\nInvalid prisma.secret.create() invocation:\n\n\nForeign key constraint failed on the field: foreign key"}

It seems that the issue is coming from this fragment:

https://github.com/HemmeligOrg/Hemmelig.app/blob/1df56be5143629bc1cdc6c01c3b32e876785b855/src/server/controllers/secret.js#L142

I tried printing the req?.user?.user_id and it was the current logged user's id:

e626fc45-8368-4d6f-9907-4671b09761bb

Any idea?

PS: I can make the PR myself, however, I'm not understanding the exact cause of this error.

bjarneo commented 8 months ago

Hm, strange error. Not sure why this is happening. What version did you come from?

bjarneo commented 7 months ago

To me, the database migration / or the database here is having an issue. Meaning it is not the application itself. Hard to verify without the database.

bjarneo commented 7 months ago

https://github.com/HemmeligOrg/Hemmelig.app/issues/246#issuecomment-1913275736