Skip to content

Despite response.ok being true I afterwards get an unauthorized error #258

Open
@ChristianKleineidam

Description

@ChristianKleineidam

Expected Behavior

If response.ok from pouchdb.logIn is true, calling pouchdb.info() shouldn't throw an error

Current Behavior

After I get response.ok from pouchdb.logIn is true, I get an "error:unauthorized" for calling pouchdb.info().

I use the following code to unsuccessfully login:

export function logIntoCouch(user: Credentials, pouch_db_name:string): Promise<PouchDB.Database<{}>> {
    const pouchOpts = {
        skip_setup: true
    }
    let pouchdb = new PouchDB(pouch_db_name, pouchOpts)

    const authOptions: AuthOptions = {
        ajax: {
            headers: {
                Authorization: "Basic " + window.btoa(user.name + ":" + user.password)
            }
        }
    }
    return new Promise<PouchDB.Database>(
        async (
            resolve: (value?: PromiseLike<PouchDB.Database> | PouchDB.Database) => void,
            reject: (reason?: any) => void
        ) => {
            await pouchdb
                .logIn(user.name, user.password, authOptions)
                .then(async (response: PouchDB.Authentication.LoginResponse) => {
                    if (response.ok) {
                        await pouchdb.info()
                            .then(resp=>{
                                console.log(resp)}
                                )
                        resolve(pouchdb)
                    } else reject(response)
                })
                .catch((error: any) => {
                    reject(error)
                })
        }
    )
}

Context

I want to login into a remote CouchDB (currently on localhost) with PouchDB that uses username/password authentification.

Your Environment

  • Version of PouchDB Authentication: "^1.1.3"
  • Version of PouchDB: "^7.1.1"
  • Platform name and version: Intellij, Jest Unittest -->
  • Operating System and version: Windows10, -->
  • Server: Apache CouchDB v. 2.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions