Skip to content

File urls are missing when logging in a User via authData. #616

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

Closed
nitrag opened this issue Feb 24, 2016 · 10 comments · Fixed by #637
Closed

File urls are missing when logging in a User via authData. #616

nitrag opened this issue Feb 24, 2016 · 10 comments · Fixed by #637
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@nitrag
Copy link

nitrag commented Feb 24, 2016

I have two ParseFiles in my Parse.User class. ProfilePic and CoverPhoto.

I've started migration over to Compose.io DBaaS. I've got Parse-Server up and running locally pointing to Compose. That's all working and I can login with a simple test user.

When logging in with a user who does NOT have any old files attached to _User (test user) the login is successful. However, when logging into a _User who still has these old files (on parse s3?) I get this error:

[ERROR] :  Script Error Tried to save an object containing an unsaved file.
//Server side, with verbose=1 returns the full object
....
  "coverPhoto": {
    "__type": "File",
    "name": "tfss-2f7fb0bd-d9e6-4ec0-b20b-80405491afcb-cover.jpg"
  },
...

If I delete the coverPhoto key in the database the error goes away so I know it's the old files causing it.

I'm guessing fileKey is supposed to grabbing the file? And it's not? There's no failure in the server side. I have confirmed that the fileKey option is set correctly and and appId matches Parse.com.

Thanks

@nlutsenko
Copy link
Contributor

@nitrag, any chance you can specify the server version you are using? We had a bug similar to this one on one of the early versions, where files where no expanded user login, but it's fixed right now on the latest release.

@nitrag
Copy link
Author

nitrag commented Feb 24, 2016

{
...
"dependencies": {
    "express": "~4.2.x",
    "kerberos": "~0.0.x",
    "underscore":"*",
    "imagemagick":"*",
    "moment":"*",
    "parse": "*",
    "parse-server": "*"
  },
  "scripts": {
    "start": "node index.js"
  },
  "engines": {
    "node": ">=4.3"
  }

I also looked in node_modules to confirm: 2.1.2 for parse-server and 1.7.1 for JS SDK

Thanks

@nlutsenko
Copy link
Contributor

#332 is the one that should have fixed it, as you can see we also have a test there.
I would recommend looking into FIlesController.expandFilesInObject - it should be called on user login.
Going to write a test that validates that this also works for legacy files in a moment.

@nlutsenko
Copy link
Contributor

Here is a quick test:

  fit("user login with files", (done) => {
    "use strict";

    let fileJSON = {__type: 'File', name: 'tfss-yolo.txt', url: 'http://files.parsetfss.com/test/tfss-yolo.txt'};
    let file = Parse.File.fromJSON(fileJSON);
    console.log(file);
    Promise.resolve().then(() => {
      return Parse.User.signUp("asdf", "zxcv", { file : file });
    }).then(() => {
      return Parse.User.logIn("asdf", "zxcv");
    }).then((user) => {
      let fileAgain = user.get('file');
      console.log(fileAgain);
      done();
    }).catch(error => {
      console.log(error);
      fail(error);
      done();
    });
  });

It's passing for me locally, no problem, so there might be something else here getting in the way.
2 pieces that I would recommend looking into:

  • Logging expandFilesInObject in FilesController.js, which is the method that should be called to construct the URL for the file
  • Logging FileCoder.databaseToJSON which converts the file from Mongo format and into REST format.

@nitrag
Copy link
Author

nitrag commented Feb 24, 2016

  expandFilesInObject(config, object) {
    console.log("expandFilesInObject...");

i don't see a result in console after running user login...should that work?
but I do see the output response:


response: {
  "objectId": "15QSQgv93Z",
  "authData": {
    "facebook": {
...
  },
  "createdAt": "2015-03-12T14:25:59.049Z",
  "updatedAt": "2016-02-24T03:46:04.326Z",
  "username": "7m7PPZaFHCuZWBCVEoYUAGEeR",
...
  "profilePicThumbnail": {
    "__type": "File",
    "name": "tfss-cebaa433-bc3a-437e-b8cf-b6348e846d2b-thumbnail.jpg"
  },

I am guessing that should it have worked the should be url parameter for profilePicThumbnail?

Also dumb question, how do I manually run tests?

@nlutsenko
Copy link
Contributor

Manually run tests - npm test .
It should log when going through /users/login.
What is the endpoint you are using to login? /users/login? or something else?
Actually a full log of request/response (the one you see when verbose logging is turned on) would help eliminate all those possibilities.

@nitrag
Copy link
Author

nitrag commented Feb 24, 2016

Hmm../users?

I'm using JS SDK 1.5.

POST /1/users { host: 'localhost:1337',
  'content-type': 'text/plain',
  'accept-language': 'en-us',
  'accept-encoding': 'gzip, deflate',
  connection: 'keep-alive',
  accept: '*/*',
  'user-agent': 'Appcelerator Titanium/5.1.1 (iPhone/9.2; iPhone OS; en_US;)',
  'content-length': '505',
  'x-titanium-id': 'ff9422b7-2258-4a97-9fff-8021dee1df65',
  'x-requested-with': 'XMLHttpRequest' } {
  "authData": {
    "facebook": {
      "id": "asdf",
      "access_token": "asdf",
      "expiration_date": "2016-04-23T22:43:58.334Z"
    }
  }
}
response: {
  "objectId": "15QSQgv93Z",
  "authData": {
    "facebook": {
      "access_token": "asdf",
      "expiration_date": "2016-04-23T22:43:57.309Z",
      "id": "asdf"
    }
  },
  "createdAt": "2015-03-12T14:25:59.049Z",
  "updatedAt": "2016-02-24T03:46:04.326Z",
  "username": "asdf",
  "sessionToken": "r:asdf",
  "first_name": "Ryan",
  "profilePicThumbnail": {
    "__type": "File",
    "name": "tfss-cebaa433-bc3a-437e-b8cf-b6348e846d2b-thumbnail.jpg"
  }
}

@nlutsenko
Copy link
Contributor

Aha! Here is where it's coming from, thanks!
You are absolutely correct - we are not expanding files in these places, looking into a fix right now.

@nlutsenko nlutsenko changed the title Script Error Tried to save an object containing an unsaved file. File urls are missing when logging in a User via authData. Feb 24, 2016
@nlutsenko nlutsenko added the type:bug Impaired feature or lacking behavior that is likely assumed label Feb 24, 2016
@nlutsenko nlutsenko self-assigned this Feb 24, 2016
@nitrag
Copy link
Author

nitrag commented Feb 25, 2016

Thanks @nlutsenko for the quick fix!

Just to confirm, it's still OK to be logging in a user with Facebook through /users? This is the original method for JS SDK (Parse.FacebookUtils.logIn).

@nlutsenko
Copy link
Contributor

Yup, that's the intended API for it. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants