MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

Basic authentication not working #75

Closed shanekoss closed 3 years ago

shanekoss commented 3 years ago

Thanks for this library - very useful!

Having an issue with basic authentication - have it set up like the documentation:

const clientOptions = {
  baseUrl: "https://api.bitbucket.org/2.0",
  request: {
    timeout: 10
  },
  auth: {
    username: "*****",
    password: "*************"
  }
};

const bitbucket = new Bitbucket(clientOptions);

bitbucket.repositories
  .listGlobal()
  .then(({ data }) => console.log(data.values))
  .catch(err => console.error(err));

I get this error:

TypeError: Cannot read property 'headers' of undefined

from index.umd.js:15:464

Any ideas?

Same credentials are working with Postman.

Thanks!

AdamSalma commented 3 years ago

I am also getting this error. +1

MunifTanjim commented 3 years ago

I've tested it in Node.js and it's working alright. Are you using it in Browser? 🤔

shanekoss commented 3 years ago

@MunifTanjim thanks so much for taking a look. I'm actually using it node.js as well.

OSX 10.15.3 Node 10.17.0

Let me know if anything you'd like to me to change or try here.

Cheers.

MunifTanjim commented 3 years ago

How is your project setup? 🤔 It shouldn't use index.umd.js for Node.js. The umd bundle is for Browser.

shanekoss commented 3 years ago

Here is my package.json:

{
  "name": "blah",
  "version": "1.0.15",
  "description": "blah",
  "main": "index.js",
  "directories": {
    "doc": "doc"
  },
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "make_changelog": "node index.js"
  },
  "repository": {
    "type": "git",
    "url": "git@bitbucket.org:something.git"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "gitlog": "git+https://github.com/andidevi/node-gitlog.git",
    "nodemon": "^2.0.4"
  },
  "nodemonConfig": {
    "watch": [
      "index.js"
    ],
    "ext": "js",
    "delay": "1"
  },
  "dependencies": {
    "bitbucket": "^2.4.1",
    "sync-request": "^6.1.0"
  }
}

No other special settings that I can think of. And for simplicity in testing - the index.js is just as above - nothing else.

Thanks.

MunifTanjim commented 3 years ago

Hey @shanekoss , can you try doing:

bitbucket.repositories
  .listGlobal({}) // pass empty object as params

does that solve your problem?

shanekoss commented 3 years ago

@MunifTanjim - thanks. doh! that was it.

AdamSalma commented 3 years ago

Fixed the solution on my end too, thanks!

Can we update the README.md to reflect this? I think we all arrived here from copying parts of the code listed in there, it would help to stop people asking the same question