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

Cloud code unable to reference Facebook auth data #1846

Closed
antonfire opened this issue May 20, 2016 · 5 comments
Closed

Cloud code unable to reference Facebook auth data #1846

antonfire opened this issue May 20, 2016 · 5 comments

Comments

@antonfire
Copy link

Check out #1271 for an ideal bug report. The closer your issue report is to that one, the more likely we are to be able to help, and the more likely we will be to fix the issue quickly!

Many members of the community use Stack Overflow and Server Fault to ask questions. Read through the existing questions or ask your own!

For database migration help, please file a bug report at https://parse.com/help#report

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!

Environment Setup

  • Server: 2.2.10, node running on ASW Elastic Beanstalk
  • Database: Mlab

Steps to reproduce

When running cloud code in parse server 2.1.6 everything works fine, upon upgrade to 2.2.10 when referencing the Facebook user id held in authdata I get an authdata undefined error. I had similar issues when I attempted to upgrade to 2.2.7, see > #1579.

I am referencing authdata in the cloud function as follows:

var currentUserFacebookID = request.user.attributes.authData.facebook.id;

As noted above this works in v2.1.6.

Logs/Trace

Elastic beanstalk logs this as:

[31merror�[39m: Uncaught internal server error. [TypeError: Cannot read property 'facebook' of undefined] TypeError: Cannot read property 'facebook' of undefined
at /var/app/current/cloud/main.js:1149:74

@steven-supersolid
Copy link
Contributor

Does this work in 2.2.8?
The bug in 2.2.7 was that a queried for user would not contain authData.
Your issue may be that request.user does not contain the attributes. There are a number of tickets about this, with some feedback in #1836

If it is the latter then one workaround is to do a fetch/query on request.user

@antonfire
Copy link
Author

No I tried 2.2.8 and the situation is the same.

@antonfire
Copy link
Author

I resolved this by wrapping my code for each cloud function in the following:

    var userAuthQuery = new Parse.Query(Parse.User);
    userAuthQuery.equalTo("username", request.user.attributes.username);
    userAuthQuery.first({useMasterKey: true,
      success: function(authDataObject) {

                 // to access authdata do this...

                var currentUserFacebookID = request.user.attributes.authData.facebook.id;

              // old code goes in here

    }, function(error) {
         response.error("get authdata info lookup failed");
    }});

@steven-supersolid
Copy link
Contributor

I've been on vacation so only just getting back to this. That is similar to what we do. I think you should be fine as username is unique. We query on request.user.id as that doesn't rely on attributes.

It's strange that the username attribute is present but not the authData so definitely something wrong there.

@miracle7
Copy link

@antonfire just fyi, @flovilmart has made a promising pull request (#2348) to finally resolve this issue, so you may be able to take out your workaround (which doesn't work for me unfortunately) in the next version if the PR makes it in. Hopefully it gets merged soon.

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