Parse server - Parse.User.become(sessionToken) - Invalid Session

1.6k views Asked by At

Trying something that should be simple, creating a new User account from an Admin dashboard using Parse server on Back4app.

Every time I try the new user is created but I am unable to switch back to the original user...

var sessionToken = Parse.User.current().getSessionToken();

                        Parse.User.signUp(email, email).then(function(newUser) {
                            Parse.User.logOut();
                            Parse.User.become(sessionToken);
                        });

Thanks

2

There are 2 answers

0
Jake T. On

logOut and become are asynchronous functions, if I'm not mistaken. So you're trying to become another user when you haven't logged out of the original user, which I don't think works.

1
Brian C On

All of these parse user functions you are using returns a promise, I suspect there is some asynchronous magic going on - try chaining them together like this and see if that fixes the issue.

Parse.User.signUp(email, email)
.then(function(newUser) 
{ return Parse.User.logOut()}
.then(function() { return Parse.User.become(sessionToken)}

For reference:

http://parseplatform.org/Parse-SDK-JS/api/classes/Parse.User.html#methods_logOut