{"action":"created","issue":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/1122","repository_url":"https://api.github.com/repos/visionmedia/superagent","labels_url":"https://api.github.com/repos/visionmedia/superagent/issues/1122/labels{/name}","comments_url":"https://api.github.com/repos/visionmedia/superagent/issues/1122/comments","events_url":"https://api.github.com/repos/visionmedia/superagent/issues/1122/events","html_url":"https://github.com/visionmedia/superagent/issues/1122","id":193822854,"number":1122,"title":"Can't find variable btoa","user":{"login":"manosim","id":6333409,"avatar_url":"https://avatars.githubusercontent.com/u/6333409?v=3","gravatar_id":"","url":"https://api.github.com/users/manosim","html_url":"https://github.com/manosim","followers_url":"https://api.github.com/users/manosim/followers","following_url":"https://api.github.com/users/manosim/following{/other_user}","gists_url":"https://api.github.com/users/manosim/gists{/gist_id}","starred_url":"https://api.github.com/users/manosim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manosim/subscriptions","organizations_url":"https://api.github.com/users/manosim/orgs","repos_url":"https://api.github.com/users/manosim/repos","events_url":"https://api.github.com/users/manosim/events{/privacy}","received_events_url":"https://api.github.com/users/manosim/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-06T16:43:48Z","updated_at":"2016-12-06T17:16:28Z","closed_at":"2016-12-06T17:16:28Z","body":"Hello and that's for making superagent! I am working on a react-native project and I am trying to make a request that has basic authentication. So my code is just:\r\n\r\n```javascript\r\n    return request\r\n      .get(`${Constants.URL}/example`)\r\n      .auth(Constants.USERNAME, Constants.PASSWORD) // <--------\r\n      .end((err, res) => {\r\n        if (err || !res.ok) {\r\n          return dispatch({ type: FETCH_DATA.FAILURE });\r\n        }\r\n        return dispatch({ type: FETCH_DATA.SUCCESS, payload: res.body });\r\n      });\r\n\r\n```\r\n\r\nAs you can see in the screenshot below, the error I am getting is due to `.auth(..., ...)`.\r\n\r\n<img width=\"1280\" alt=\"screen shot 2016-12-06 at 16 30 23\" src=\"https://cloud.githubusercontent.com/assets/6333409/20934414/f68e1c56-bbd2-11e6-9c23-ee6fd84d2d40.png\">\r\n\r\nSo if I comment out `.auth(..., ...)` the it works but obviously the request is failing. After reading the source code, I can see that `btoa` is supposed to be set in the window and since this is a react-native app there is no `window`.\r\n\r\n### A possible fix\r\nI did find out that in the tests you are doing [this](https://github.com/visionmedia/superagent/blob/5e841d6dcad7ae3c2d13a31d00c9063ae7e56ee7/test/client/request.js#L143): `window.btoa = window.btoa || require('Base64').btoa;`\r\n\r\nI can open a PR that has this change and also move the `Base64` dependency from `devDevependencies` to `dependencies` if you think this is the correct approach.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/visionmedia/superagent/issues/comments/265211201","html_url":"https://github.com/visionmedia/superagent/issues/1122#issuecomment-265211201","issue_url":"https://api.github.com/repos/visionmedia/superagent/issues/1122","id":265211201,"user":{"login":"manosim","id":6333409,"avatar_url":"https://avatars.githubusercontent.com/u/6333409?v=3","gravatar_id":"","url":"https://api.github.com/users/manosim","html_url":"https://github.com/manosim","followers_url":"https://api.github.com/users/manosim/followers","following_url":"https://api.github.com/users/manosim/following{/other_user}","gists_url":"https://api.github.com/users/manosim/gists{/gist_id}","starred_url":"https://api.github.com/users/manosim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manosim/subscriptions","organizations_url":"https://api.github.com/users/manosim/orgs","repos_url":"https://api.github.com/users/manosim/repos","events_url":"https://api.github.com/users/manosim/events{/privacy}","received_events_url":"https://api.github.com/users/manosim/received_events","type":"User","site_admin":false},"created_at":"2016-12-06T17:16:28Z","updated_at":"2016-12-06T17:16:28Z","body":"@pornel Agreed and thank you for your quick reply! For any future reference the way to fix this is:\r\n\r\nInstall `Base64` (note the capital **B**) from npm:\r\n\r\n    npm install --save Base64\r\n\r\nThen in your code before requiring `superagent` do:\r\n\r\n    window.btoa = require('Base64').btoa;\r\n"}}
{"actor":{"display_login":"manosim"}}