So today Parse.User.become function stopped working for me.
Before it worked ok but now I always get this error:
{"code":101,"message":"invalid session"}
For testing this I made simple functions:
app.get('/login/me',function(req,res){
var curr = Parse.User.current();
res.json({user:curr,success:true,token:curr.getSessionToken()});
});
app.get('/test',function(req,res){
var a = "r:wqBOELvWLjFXxX6r7Nv6r8a5Z"; //token returned from /login/me
Parse.User.become(a).then(function (user) {
res.json({success:true});
}, function (error) {
Parse.User.logOut();
res.json(error);
});
});
I tried cloning whole app and it still doesn't work.
Any idea whats wrong?
Where are you running this Parse.User.current()? since there is no current user in Node, and become also shouldn't be done serverside...
This is Cloud Code. And if its called from browser where user is logged in then Parse.User.current() works just fine.
If become shouldn't be used on Cloud Code do I have to manually set some other sessionToken (to identify user) and then manually search other objects based on this user id?
You should read this https://github.com/ParsePlatform/parse-server/wiki/Compatibility-with-Hosted-Parse
Parse.User.current() is dead
.become is dead
{sessionToken: req.user.getSessionToken(), succes: ..., error:...} is the new way forward moving from parse.com to parse-server :)
How is the situation handled where the user isn't known but the sessionToken is and you wish to retrieve the user from the sessionToken (in Cloud Code)?
@patrickbdev how is the sessionToken transmitted to the server? If it's part of an 'authenticated call', the user will be available on req.user. Otherwise you ca make a query on _Session, with including the user property.
Here is how we internally resolve the sessionToken sent to the server part of the request headers.
Similarly you should be able to do:
let query = new Parse.Query('_Session')
query.equalTo('sessionToken', sessionToken);
query.include('user');
query.first({useMasterKey: true}).then(function(session)聽{
let user = session.get('user');
}, function(err)聽{
// something bad happened, not found etc...
});
@flovilmart is this how I can grab the current user? If I have there sessionToken stored as a cookie, could I just query the _Session class and have the current user?
Most helpful comment
@patrickbdev how is the sessionToken transmitted to the server? If it's part of an 'authenticated call', the user will be available on
req.user. Otherwise you ca make a query on _Session, with including the user property.Here is how we internally resolve the sessionToken sent to the server part of the request headers.
Similarly you should be able to do: