Authentication sporadically fails when postgres has a defined search path #4404
-
I have a multitenant app in which tenants share a database and are separated by the schema. To switch between them, I use a middleware that gets the request subdomain and switches connections:
The database config looks something like this:
For the most part, this works as intended - as I switch subdomains, so does the schema. However, seemingly randomly, authentication fails as I visit routes protected by auth middleware.
Sometimes, auth fails on the first request following authentication. Other times, I can make a bunch of requests to auth-protected routes before it fails. Oddly, if I restart the process, authentication with the same token works again. I don't have issues when accessing unprotected routes that also query the database, so I don't think this is a database issue. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This approach is buggy in first place, because Node.js can handle multiple requests in parallel and therefore the schema set by second first will overwrite the schema set by first request. Also, it has nothing to do with Auth at all, you are overwriting global properties while handling concurrent requests |
Beta Was this translation helpful? Give feedback.
This approach is buggy in first place, because Node.js can handle multiple requests in parallel and therefore the schema set by second first will overwrite the schema set by first request.
Also, it has nothing to do with Auth at all, you are overwriting global properties while handling concurrent requests