mozilla / django-browserid

Django application for adding BrowserID support.
Mozilla Public License 2.0
180 stars 80 forks source link

Logout not working due to promise never resolved #238

Closed peterbe closed 10 years ago

peterbe commented 10 years ago

I'm using 8a2d717d1e9cb83ef4e9ef86eff15f47f2d66751 in crash stats and logout doesn't work.

I hastily debugged it down to this:

        logout: function logout() {
            return django_browserid.getInfo().then(function(info) {
                logoutDeferred = $.Deferred();
                navigator.id.logout();

                return logoutDeferred.then(function() {   // THIS NEVER HAPPENS
                    return $.ajax(info.logoutUrl, {
                        type: 'POST',
                        headers: {'X-CSRFToken': info.csrfToken},
                    });
                });
            });
        },

The problem there is that it returns a promise that, on resolve, returns a promise. Did I get that right? I think the solution is to rewrite it to the following:

        logout: function logout() {
            return django_browserid.getInfo().then(function(info) {
                logoutDeferred = $.Deferred();
                navigator.id.logout();
                return $.ajax(info.logoutUrl, {
                        type: 'POST',
                        headers: {'X-CSRFToken': info.csrfToken},
                    });
            });
        },

That makes logout work again. Perhaps it's something else fundamentally broken and this is just a hackaround.

peterbe commented 10 years ago

Ping @Osmose I'm happy to provide the PR but I'd love your eyes on it to see that I haven't misunderstood something obvious.

Osmose commented 10 years ago

I'm PyConning, I will try my darndest to get a look at this ASAP <3

peterbe commented 10 years ago

I think I'm getting this wrong somehow. I just tried in a simple sample project with the extreme basics and logout worked. So, it would seem I'm doing something wrong in the Socorro code! /me investigating

peterbe commented 10 years ago

I'm confused but also bored.

It's not reproducible in master and when I tried to check out 8a2d717d1e9cb83ef4e9ef86eff15f47f2d66751 (which is what I had in socorro) it still worked (i.e. was not reproducible).

And for socorro, I just upgraded to master of django-browserid and the problem went away. I'm stumped but happy to move on with my life.