Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChristianKleineidam opened this issue Nov 14, 2019 · 2 comments

Comments

@ChristianKleineidam
Copy link

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
@komorebi-san
Copy link

I am getting the same thing.

@SinanGabel
Copy link

SinanGabel commented Mar 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants