You are not a server admin error
- Dominant language
- JavaScript
- Stars
- 689
- Forks
- 167
- Avg merge
- 1h
- Merged PRs (30d)
- 1
Description
## Expected Behavior
Stable connection to CouchDB
## Current Behavior
Sometimes, I receive the "You are not a server admin" error when performing requests using my back-end server. I suppose that it is due to the way that I create the DB connection.
I'm currently using the following code:
```
export const databaseConnection: ServerScope = nano({
url: environment.databaseConfiguration.url,
requestDefaults: {
// enable cookie-based authentication
// Reference: https://www.npmjs.com/package/nano#using-cookie-authentication
jar: true,
auth: {
username: environment.databaseConfiguration.username,
password: environment.databaseConfiguration.password,
},
},
```
Later, in my repository code, I simply use that constant to make database calls:
```
public ensureThatWorkspaceExists(workspaceId: string): Observable {
return from(this.databaseConnection.db.list()).pipe(
switchMap((databasesList) => {
const databaseExists = databasesList.filter((existingDatabase) => {
return existingDatabase === workspaceId;
});
if (databaseExists.length === 0) {
throw new GateTechnicalError(GateTechnicalErrorType.DATABASE_NOT_FOUND);
}
return of(true);
}),
);
}
```
## Context
I've tried to configure cookie authentication in order to streamline things, but I suppose that I'm not using it correctly?
What surprises me is that it seems to work, most of the time, except that:
* it seems to fail if my API server is started before CouchDB
* it seems to fail after a while (when the cookie expires??)
When it fails, I get the "You are not a server admin" response when I try to make calls. Restarting the back-end server (not Couch) fixes the issue temporarily.
What would you recommend to avoid having such issues?
## Your Environment
* Version used: 8.2.2
* Browser Name and version: N/A
* Operating System and version (desktop or mobile): Linux (Ubuntu 20.20)
* Link to your project: N/A
Contributor guide
Research direction
Start with the nano connection setup using requestDefaults, cookie authentication, and the supplied auth credentials, then trace the calls from ensureThatWorkspaceExists through databaseConnection.db.list(). Reproduce the failure when CouchDB starts later and after the cookie expires. Done means authenticated database requests remain stable across startup ordering and cookie expiry, with the behavior covered by appropriate regression checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100