Skip to content
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

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

Closed
sprabs opened this issue Mar 2, 2016 · 13 comments

Comments

@sprabs
Copy link

sprabs commented Mar 2, 2016

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?

@nitrag
Copy link

nitrag commented Mar 3, 2016

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.

@sprabs
Copy link
Author

sprabs commented Mar 3, 2016

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.

@flovilmart
Copy link
Contributor

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

@sprabs
Copy link
Author

sprabs commented Mar 3, 2016

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

@flovilmart
Copy link
Contributor

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

@nitrag
Copy link

nitrag commented Mar 3, 2016

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.

@flovilmart
Copy link
Contributor

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

@sprabs
Copy link
Author

sprabs commented Mar 3, 2016

@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?

@gfosco
Copy link
Contributor

gfosco commented Mar 6, 2016

@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
Copy link
Contributor

gfosco commented Mar 6, 2016

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

@gfosco gfosco closed this as completed Mar 6, 2016
@RafaRuiz
Copy link

RafaRuiz commented Jul 23, 2016

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

@alexblack
Copy link

alexblack commented Oct 4, 2016

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)

@RafaRuiz
Copy link

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.

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

6 participants