Skip to content

Logout doesn't seem to work in 1.7.0 #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Feb 5, 2016 · 24 comments
Closed

Logout doesn't seem to work in 1.7.0 #200

ghost opened this issue Feb 5, 2016 · 24 comments

Comments

@ghost
Copy link

ghost commented Feb 5, 2016

Added it via npm, required parse and used browserify. Login works but logout doesn't seem to work. I don't see a request going out for logout. Could be a bug. I'm using parse server.

I noticed parsecdn is giving 1.6.14, so downgraded to 1.6.14 and logout works.

@andrewimm
Copy link
Contributor

Can you provide some more information? Some sample code?

@andrewimm
Copy link
Contributor

For context: Parse has a set of internal integration tests we run against a production version of the API. If the logout test were failing, we would have seen a test failure before shipping the SDK.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Yeah I thought the test would have failed.. I'm not sure if there is something wrong with my code. The same code works with 1.6.14. I'm using it with react. I'll create a sample and see if 1.7 fails there also. I'll let you know. Thanks!

@andrewimm
Copy link
Contributor

How are you integrating this with React? I'm guessing that the issue is more likely due to the changes we made to upgrade default behavior of Promises, than anything logOut specific.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Here is the component after the user is logged in. I click on logout and it doesn't work.

var Parse = require('parse');
var React = require('react');

var HomeUser = React.createClass({
  render: function() {
    return (
        <div>
          logged in
          <a href='#' onClick={ ()=>{ Parse.User.logOut(); } }>Logout</a>
          <a href='#' onClick={ ()=>{ console.log(Parse.User.current()); } }>user</a>
        </div>
    );
  }
});

module.exports = HomeUser;

@andrewimm
Copy link
Contributor

Replace Parse.User.logOut() with

Parse.User.logOut().then(() => {
  console.log('succeeded');
}, (error) => {
  console.log('error', error);
});

That'll help determine if it's erroring out, or if it's succeeding without hitting the network.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

I think I tried that. It gave success, but nothing happens. I'll try again to be sure.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

It is giving success, but I don't see a network request. I refresh the page, login stays and clicked on logout with same result.

@andrewimm
Copy link
Contributor

I'd also check the value of the current user, and the session token on the current user.

First, check that Parse.User.currentAsync().then((user) => { ... }) resolves with the same user being shown by Parse.User.current() in your code. If not, you're somehow deleting the user from disk somewhere without the cache being updated.
Next, check the value of Parse.User.current().getSessionToken(). Only if it exists, and begins with 'r:' will the SDK hit the network.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

User.currentAsync and User.current are showing the same user. getSessionToken is showing undefined. I see the user info in local storage. Only when I manually delete it and then refresh the user is logged out.

The only components that I have now are App, login, register, and userHome. I'm logging-in in login component, and userHome has the logout. App has the Parse initialize calls.

@andrewimm
Copy link
Contributor

If getSessionToken returns undefined, then it won't go out to the network, since the user isn't really "logged in." Sounds like the issue is in the log in process, either from your code, or a bug with Parse Server.

@andrewimm
Copy link
Contributor

Doesn't quite explain why it works in 1.6.14 but fails in 1.7.0, though

@ghost
Copy link
Author

ghost commented Feb 5, 2016

I installed 1.6.14 with the same code, and get the same user for currentAsync and current. sessionToken is undefined. Clicked on logout and it works.

Also I did not restart parse server.

@andrewimm
Copy link
Contributor

If session token is undefined, then that's the real issue. I'd look at the network request to see if the session token is coming back on it, but this sounds like a parse-server issue.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Also while in 1.6.14, logged out and logged in. Then sessiontoken is r:xxxxx.

Changed to 1.7

  1. Deleted local storage keys
  2. logged in
  3. User is the same
  4. Session token is r:xxxxx
  5. Logout sent a request
  6. Logout did not happen
  7. User is the same
  8. sessiontoken is undefined
  9. Logout gives success, but does not send a request
  10. User is the same for User.currentAsync and User.current

@andrewimm
Copy link
Contributor

Can you explain step 6? You say logout sent a request... that sounds like everything worked to me

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Sorry. Updated.

@andrewimm
Copy link
Contributor

Okay, now I'm confused again. You say logout sent a request, and after that sessionToken is undefined. That is all working as expected. The user object will still exist, but Parse.User.current() should no longer return it. Is that what you mean by "6. Logout did not happen" ? Otherwise, I'm not seeing an issue here.

Since React is clearly not affecting this, I'd appreciate it if you could create a simple use case that doesn't involve React, that reproduces the error you're seeing. A test case in the unit test suite that fails for now would be even better. Then we can get started finding a solution to the bug, if it exists.

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Parse.User.current() is giving the user even after I click on logout and the request goes out. Here is a screenshot. Sorry for the confusion. I'll create a sample app, will be easier to debug.

screenshot from 2016-02-04 21 38 35

@ghost
Copy link
Author

ghost commented Feb 5, 2016

Narrowed it down. It's parse-react. The moment I just require parse-react this issue comes up.

var Parse = require('parse');
// var ParseReact = require('parse-react');

Parse.initialize('app','unused');
Parse.serverURL = '/parse';

Parse.User.logIn('test', '12312', {
  success: function(user) {
    console.log('success', user);
  },
  error: function(user, error) {
    console.log('error', error);
  }
});


setTimeout(function(){
  Parse.User.logOut().then(() => {
    console.log('succeeded');
    console.log(Parse.User.current());
  }, (error) => {
    console.log('error', error);
    console.log(Parse.User.current());
  });
}, 3000);

without-parse-react
with-parse-react

@TylerBrock
Copy link
Contributor

Ah ha, I'm having this same problem! Thank you.

On Thu, Feb 4, 2016 at 8:40 PM M [email protected] wrote:

Narrowed it down. It's parse-react. The moment I just require parse-react
this issue comes up.

var Parse = require('parse');
// var ParseReact = require('parse-react');

Parse.initialize('app','unused');
Parse.serverURL = '/parse';

Parse.User.logIn('test', '12312', {
success: function(user) {
console.log('success', user);
},
error: function(user, error) {
console.log('error', error);
}
});

setTimeout(function(){
Parse.User.logOut().then(() => {
console.log('succeeded');
console.log(Parse.User.current());
}, (error) => {
console.log('error', error);
console.log(Parse.User.current());
});
}, 3000);


Reply to this email directly or view it on GitHub
#200 (comment)
.

@ghost
Copy link
Author

ghost commented Feb 6, 2016

Could be related parse-community/ParseReact#161

@andrewimm
Copy link
Contributor

Closing here, as it's related to Parse-React. I'll see if I can patch that add-on SDK sometime soon.

@albertolive
Copy link

I'm having the same issue with Parse.User.logOut(). When I call that function, it doesn't remove from localStorage, as it did before, the keys related to Parse. The only thing I can do now is do it myself.

This is my code:

logOut:function() {
    var that = this;
    var currentUser = Parse.User.current();
    currentUser.save().then(
        function(success) {
            Parse.User.logOut().then(
                function(success) {
                    var currentUser = Parse.User.current();
                    if (currentUser) {
                        //I have current user always.
                    }
                    that.history.pushState(null, '/login');
                },
                function(error) {
                    console.log(error);
                    that.history.pushState(null, '/main/404');
                }
            );
        },
        function(error) {
            console.log(error);
            that.history.pushState(null, '/main/404');
        }
    );

In localStorage I have this two parse related keys:

Key Value
Parse/bU9RT7hUMWEtPrh310AjXXXXXXXXXXXXXXXXX/currentUser {"username":"albert....". ".."}
Parse/bU9RT7hUMWEtPrh310AjXXXXXXXXXXXXXXXXX/currentUser 47dc451d-b66f-55e8-f405-xxxxxxxxxx

The only thing changed in localStorage when I press logout is with sessionToken, that's missing.

I haven't changed anything in past month and I'm using React but not using Parse-React.

"parse": "^1.6.0", "react": "^0.14.3",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants