Shelf-nu / shelf.nu

shelf is open source Asset Management Infrastructure for absolutely everyone.
https://shelf.nu
GNU Affero General Public License v3.0
1.67k stars 145 forks source link

[Bug]: OTP token cannot be validated / "prepared statement 's0' does not exist" #1054

Closed oleggtro closed 1 month ago

oleggtro commented 1 month ago

Contact Details

ole@oleggtro.com

What happened?

I am trying to set up a local instance of shelf for evaluation purposes for my company and running into the same issue every time. The SMTP setup is correct (as the emails get delivered successfully). I also believe that the DB connection succeeds as there is no other mention of it and migrations also get applied successfully.

Is this a user error or a real bug?

Steps to reproduce:

  1. Set up shelf according to the docker guide in docs/getting_started.md
  2. Try to create an account
  3. Receive the OTP token
  4. Try to put it in and confirm
  5. error. ("Failed to find user")

What is the expected behaviour?

Take the (correct) OTP Token and confirm the user account.

Version

Self-hosted

What browsers are you seeing the problem on?

Chrome, Safari

Relevant log output

{"level":50,"time":1718231411488,"pid":87,"hostname":"da5493697a34","err":{"cause":{"name":"PrismaClientUnknownRequestError","clientVersion":"5.15.0","stack":"PrismaClientUnknownRequestError: \nInvalid `prisma.user.findUnique()` invocation:\n\n\nError occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(PostgresError { code: \"26000\", message: \"prepared statement \\\"s0\\\" does not exist\", severity: \"ERROR\", detail: None, column: None, hint: None }), transient: false })\n    at In.handleRequestError (/src/node_modules/@prisma/client/runtime/library.js:122:7067)\n    at In.handleAndLogRequestError (/src/node_modules/@prisma/client/runtime/library.js:122:6211)\n    at In.request (/src/node_modules/@prisma/client/runtime/library.js:122:5919)\n    at async l (/src/node_modules/@prisma/client/runtime/library.js:127:11167)\n    at async findUserByEmail (file:///src/build/server/remix.js:8671:12)\n    at async action$12 (file:///src/build/server/remix.js:10076:36)\n    at async Object.callRouteActionRR (/src/node_modules/@remix-run/server-runtime/dist/data.js:35:16)\n    at async callLoaderOrAction (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:4166:16)\n    at async submit (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:3520:16)\n    at async queryImpl (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:3478:22)"},"label":"User","additionalData":{"email":"ole.donnermeyer@icloud.com"},"shouldBeCaptured":true,"status":500,"traceId":"r53lvdkg30pk6alajki009xb","name":"ShelfError","message":"Failed to find user","stack":"ShelfError: Failed to find user\n    at makeShelfError (file:///src/build/server/remix.js:115:12)\n    at action$12 (file:///src/build/server/remix.js:10099:20)\n    at async Object.callRouteActionRR (/src/node_modules/@remix-run/server-runtime/dist/data.js:35:16)\n    at async callLoaderOrAction (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:4166:16)\n    at async submit (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:3520:16)\n    at async queryImpl (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:3478:22)\n    at async Object.queryRoute (/src/node_modules/@remix-run/server-runtime/node_modules/@remix-run/router/dist/router.cjs.js:3447:18)\n    at async handleDataRequestRR (/src/node_modules/@remix-run/server-runtime/dist/server.js:122:20)\n    at async requestHandler (/src/node_modules/@remix-run/server-runtime/dist/server.js:94:18)\n    at async file:///src/node_modules/remix-hono/build/handler.js:7:16"},"msg":"Failed to find user"}
DonKoko commented 1 month ago

Hey @oleggtro. The prepeared statement issue tells me that the DB connection string is not correctly placed. You need to connect to supabase pooler in transaction mode.

As for the migrations, those use a different connection string than the app, due to how supabase and prisma work. Here is one example of an issue describing it: https://github.com/prisma/prisma/issues/11643

oleggtro commented 1 month ago

Oh sorry, so it was indeed an error on my end. My DATABASE_URL was indeed malformed, I was missing the pgbouncer=true at the end. Thanks!

DonKoko commented 1 month ago

@oleggtro yeah that basically tells supavisor to simulate the pgBouncer prepared statements. Glad its resolved.