oauth-io / oauth-js

OAuth that just works ! This is the JavaScript SDK for OAuth.io

Home Page:https://oauth.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Cannot read property 'match' of undefined"

MicahZoltu opened this issue · comments

https://github.com/oauth-io/oauth-js/blob/master/dist/oauth.js#L621

class Foo {
    constructor() {
        OAuth.initialize('ySUBeXemKN-_QodJajU-HuWUdVM');
    }

    onClick() {
        OAuth.popup('github', { cache: true }).done((auth: any) => {
            User.signin(auth).fail((error: any) => console.log(error));
        });
    }
}
  • Click button.
  • Sign-in.
  • Notice error due to missing email.
  • Click button again.
  • Notice exception (not error through .fail handler).
Unhandled promise rejection TypeError: Cannot read property 'match' of undefined
    at module.exports.http.doRequest (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:623:27)
    at Object.module.exports.http (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:674:16)
    at module.exports.mkHttp (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:793:21)
    at jQuery.param.add (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:4600:41)
    at buildParams (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:4589:3)
    at Function.jQuery.param (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:4620:4)
    at Function.jQuery.extend.ajax (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.js:4280:20)
    at Object.post (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.min.js:32:18)
    at Object.signin (http://localhost:3000/jspm_packages/bower/oauth.io@0.4.3/dist/oauth.min.js:1187:21)

The problem appears to be that auth doesn't have a toJson method on it when it is retrieved from the cache.

This is where calling popup retrieves from the cache:
https://github.com/oauth-io/oauth-js/blob/master/coffee/lib/oauth.coffee#L89

This is where toJson is called if it exists:
https://github.com/oauth-io/oauth-js/blob/master/coffee/lib/user.coffee#L139

This is where toJson is defined:
https://github.com/oauth-io/oauth-js/blob/master/coffee/lib/request.coffee#L305-L315