You are not a server admin error
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<boolean> {
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
is this by chance against a cluster (and not a single node)?
No, it is a single node. For the moment, I've disabled cookie authentication as the issue continued to occur from time to time.
is this maybe related to your configured cookie session time?
I think so, yes. I actually disabled the following setting: "allow_persistent_cookies". I guess I wanted to be overprotective, by avoiding "forever" cookies, and instead created a situation where I have "never" cookies? ;-)