{"action":"opened","issue":{"url":"https://api.github.com/repos/auth0/auth0.js/issues/189","repository_url":"https://api.github.com/repos/auth0/auth0.js","labels_url":"https://api.github.com/repos/auth0/auth0.js/issues/189/labels{/name}","comments_url":"https://api.github.com/repos/auth0/auth0.js/issues/189/comments","events_url":"https://api.github.com/repos/auth0/auth0.js/issues/189/events","html_url":"https://github.com/auth0/auth0.js/issues/189","id":172219053,"number":189,"title":"Checking callback arity to determine whether or not to redirect breaks with default args","user":{"login":"sgtpepper43","id":2449014,"avatar_url":"https://avatars.githubusercontent.com/u/2449014?v=3","gravatar_id":"","url":"https://api.github.com/users/sgtpepper43","html_url":"https://github.com/sgtpepper43","followers_url":"https://api.github.com/users/sgtpepper43/followers","following_url":"https://api.github.com/users/sgtpepper43/following{/other_user}","gists_url":"https://api.github.com/users/sgtpepper43/gists{/gist_id}","starred_url":"https://api.github.com/users/sgtpepper43/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgtpepper43/subscriptions","organizations_url":"https://api.github.com/users/sgtpepper43/orgs","repos_url":"https://api.github.com/users/sgtpepper43/repos","events_url":"https://api.github.com/users/sgtpepper43/events{/privacy}","received_events_url":"https://api.github.com/users/sgtpepper43/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-19T20:57:19Z","updated_at":"2016-08-19T20:57:19Z","closed_at":null,"body":"In the `auth0.login` method, in order to determine whether or not auth0 should make a redirect, you check the arity of the callback function to see if the callback expects a response, [here](https://github.com/auth0/auth0.js/blob/master/index.js#L1293). Also see the comment above for more explanation. The problem is that, [according to the javascript spec](http://www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-expectedargumentcount), default arguments do not count towards `function.length`. So if anyone sets a default for `err` or `response`, it will redirect. It would be much better to just provide a `redirect: true|false` option.\r\n\r\nIn my particular case, my callback looks like this:\r\n`(err, { idToken } = {}) =>`. I only need the `idToken`, so I'm just destructuring it off of the response. When there's an error, though, the response object is `undefined`. In that case, I have it default to an empty object ` = {}` so that it won't throw any errors. But babel transpiles that like so:\r\n```javascript\r\n(function (err) {\r\n  var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];\r\n\r\n  var idToken = _ref.idToken;\r\n})\r\n```\r\nWhich clearly sets the arity to 1, which it ought to. To get around this I simply do my destructuring on the next line, but that's not really a satisfactory solution, especially considering others might run into this problem and just have no idea why it's not working. I only found it because I only just migrated the code to es6; if this were a new project and I'd never used auth0 before I would've had no idea what was breaking."}}
{"actor":{"display_login":"sgtpepper43"}}