parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Inconsistency with request.user (resulting in null in some cases) after migration

Open sprabs opened this issue 10 years ago • 13 comments

We have setup our own Parse Server on AWS and have gone through the guide. Our deployed Cloud Code is working in some cases, but we are hitting issues in our conversion from Parse.User.current() to request.user. It works for basic information like to retrieve the current user's id, but when we normally were doing something like Parse.User.current().get("favoriteTeams") that does not seem to convert as expected to request.user.get("favoriteTeams").

We consistently see this (or a similar) error:

Uncaught internal server error. [TypeError: Cannot read property 'get' of null] TypeError: Cannot read property 'get' of null at Object.fetchNewPostsData (/var/app/current/cloud/main.js:2973:42)

I have also noticed this in the logs:

BUG: the handler did not include a "response" field

I have not been able to find documentation related to this and Hector told me to post the issue here. How do you suggest we resolve this issue?

sprabs avatar Mar 02 '16 22:03 sprabs

As I have been reading, I understand that if your user on the client app is still sending a non-revocable session (old method) then this will result in request.user = null and cloud code will fail. Check your headers in your Post. If you're using JS SDK you'll need to look at a wireshark trace because the session info and application info is in the data and not the headers.

nitrag avatar Mar 03 '16 00:03 nitrag

I'd like to add that we currently have no issues when pointing to parse.com. This only manifests when pointing to our own Parse Server. Are you saying that the issues we are hitting are due to an issue on the client side itself? We have not made any changes for sessions on iOS or Android.

sprabs avatar Mar 03 '16 00:03 sprabs

@sprabs do you use revocable sessions or the old sessions?

flovilmart avatar Mar 03 '16 00:03 flovilmart

@flovilmart we are still using the old sessions in production. It works fine when pointing to parse.com.

sprabs avatar Mar 03 '16 00:03 sprabs

I belive old sessions are not supported in parse-server, and they most likely won't be supported.

flovilmart avatar Mar 03 '16 00:03 flovilmart

Yes, but here-in lies the problem. Parse-Server is not reporting that user is not using revocable session. This causes silent failures (request.user = null). We need to throw an error so the user can re-login.

nitrag avatar Mar 03 '16 00:03 nitrag

If the client don't enable revokable sessions that won't help either. You should migrate your users to revokable sessions before starting using parse-server. there https://www.parse.com/tutorials/session-migration-tutorial

flovilmart avatar Mar 03 '16 01:03 flovilmart

@flovilmart @nitrag Thanks for this feedback. I just followed the documentation and added the necessary code on the iOS client side and created a new user in our test environment.

Now, I am hitting a new issue: Uncaught internal server error. [TypeError: Cannot read property 'query' of undefined] TypeError: Cannot read property 'query' of undefined

My code is querying a relation. It doesn't seem to like this. We query relations a lot. Is this a bug with parse-server or is there some modifications that I need to make in order to get this to work?

sprabs avatar Mar 03 '16 01:03 sprabs

@sprabs You'd need to find out which line is accessing a .query property, and whatever object that is, you should be checking it is defined first.

gfosco avatar Mar 06 '16 22:03 gfosco

This is now a duplicate of #782. Please continue discussion there.

gfosco avatar Mar 06 '16 23:03 gfosco

Hello @gfosco I think #782 is another discussion regarding the query.

I'm still with this issue with the request.user == null. I can't reproduce the problem.

Still, I'm trying to make the user to relog-in when this happens, or the sessionToken is invalid. So in my cloud I have this code:

if (!request.user) { response.error("INVALID_SESSION_TOKEN"); return; }

So in Android, in case I get error = INVALID_SESSION_TOKEN (209) or error = 141 + message = "INVALID_SESSION_TOKEN", I make the user log in again:

if (e != null && (e.getCode() == ParseException.INVALID_SESSION_TOKEN || is141INVALIDTOKEN(e))) { if (ParseUser.getCurrentUser() != null) { loggingOut = true; final ProgressDialog pd = ProgressDialog.show(activity, null, activity.getString(R.string.Un_momento)); ParseUser.getCurrentUser().logOutInBackground(new LogOutCallback() { @Override public void done(ParseException e) { loggingOut = false; if (pd != null && pd.isShowing()) pd.dismiss(); Intent intent = new Intent(activity, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); activity.startActivity(intent); } }); } return; }

but request.user is still null so this becomes in a infinite loop :(.

In Android:

I've been debugging the whole process: a) I wait until ParseUser.enableRevocableSessionInBackground() is completed with no error. b) Log in with my user c) When I log in, I check my _Session object created in my MongoDB and I print my ParseUser.getCurrentUser().getSessionToken() and both are the same. d) then I make a call to the cloud function and request.user is still null. I've checked the headers by sniffing and everything is OK. e) It was working at 20.20 today and not working anymore at 22:25 (now). f) cry.

EDIT (more specific):

  1. Log in, created _Session object: image

so the sessionToken is r:a425239d4184cd98b9b693bbdedfbc9c

  1. Make call cloud function (sniff log):

POST /parse-debug/functions/getHomeAudios HTTP/1.1 X-Parse-OS-Version: 6.0.1 X-Parse-App-Build-Version: 17 X-Parse-Client-Key: **** (hidden) X-Parse-Client-Version: a1.13.0 X-Parse-App-Display-Version: 1.15.17 X-Parse-Installation-Id: d7ea4fa0-b4dc-4eff-9b7d-ff53a1424dcb User-Agent: Parse Android SDK 1.13.0 (com.pronuntiapp.debug.uat/17) API Level 23 X-Parse-Session-Token: r:a425239d4184cd98b9b693bbdedfbc9c X-Parse-Application-Id: **** (hidden) Content-Type: applicati¡á“WÇX Content-Length: 346 Host: 46.101.89.192:1338 Connection: Keep-Alive Accept-Encoding: gzip

  1. fallen in request.user == null

RafaRuiz avatar Jul 23 '16 21:07 RafaRuiz

Was there a solution to this? I'm facing the same issue against parse.com (not parse-server), with the same steps from above:

a) I wait until ParseUser.enableRevocableSessionInBackground() is completed with no error.
b) Log in with my user
c) When I log in, I check my _Session object created in my MongoDB and I print my ParseUser.getCurrentUser().getSessionToken() and both are the same.
d) then I make a call to the cloud function and request.user is still null. I've checked the headers by sniffing and everything is OK.
e) It was working at 20.20 today and not working anymore at 22:25 (now).
f) cry.

(We have just started using ParseUser.enableRevocableSessionInBackground() in our Android app in preparation for migrating to parse-server)

alexblack avatar Oct 04 '16 05:10 alexblack

In my case, calling to a Parse Cloud function was ok, but inside the function I was calling another separate Cloud function. That was where I was losing my request.user. So what I had to do is passing the original sessionToken to the function when calling Parse.Cloud.run.

RafaRuiz avatar Nov 17 '16 12:11 RafaRuiz