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

fix: original object not retrieved when user logs in with third party auth

Open Meglali20 opened this issue 2 years ago • 22 comments

New Pull Request Checklist

  • [x] I am not disclosing a vulnerability.
  • [x] I am creating this PR in reference to an issue.

Issue Description

Related issue: issue#7737

Approach

TODOs before merging

  • [ ] Add tests
  • [ ] Add changes to documentation (guides, repository pages, in-code descriptions)
  • [ ] Add security check
  • [ ] Add new Parse Error codes to Parse JS SDK
  • [x] A changelog entry is created automatically using the pull request title (do not manually add a changelog entry)

Meglali20 avatar Dec 16 '21 16:12 Meglali20

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

I will reformat the title to use the proper commit message syntax.

@davimacedo how would you suggest using the same account to log in twice?

Meglali20 avatar Apr 05 '22 15:04 Meglali20

@Meglali20 I've just checked getMockFacebookProvider and it actually returns same account every time, so you are good with that. It would be good if you could login the user twice and have a success flow calling done() function in the test though.

davimacedo avatar Apr 05 '22 18:04 davimacedo

@davimacedo why a success flow on login? that would work but the purpose is to retrieve the original user to check if the user is new or just performing a login. actually, when I ran the test I had no issue and the test demonstrated that it fails and it isn't retrieving the original object on the second login, and the auth data is there.

Meglali20 avatar Apr 06 '22 15:04 Meglali20

When we write a test for a use-case, we should have a fail path (to check the behavior that we did not expect to happen) and a success path (to check the behavior that we expect to happen). In the way you wrote your test, it will always fail (even if the supposed bug is later on fixed), because there is no call to the done() function. Therefore, we cannot be sure that the test is failing because of a bug that is actually happening or if it is because there is no success path. I'd expect to have a test case that succeeds when Parse.User._logInWith('facebook') is called a single time, and fails when Parse.User._logInWith('facebook') is called twice. Maybe you will have to use getMockFacebookProviderWithIdToken() instead of getMockFacebookProvider () to pass an account that was not used by the other tests. It would be good to also have some message in here done.fail() so we can also easily see that the test is failing when hitting this line.

I've seen you rebases with latest alpha. Is the problem still happening?

davimacedo avatar Apr 06 '22 16:04 davimacedo

@davimacedo yes using now version 5.3.0-alpha.4 and the problem is still there.

Meglali20 avatar Apr 06 '22 17:04 Meglali20

I recently removed many done() from jasmine tests (can't remember which repo), because that was indicated to be a deprecated syntax. Instead of using done(), the test should just return void and not fail. If a fail is expected, use expect.toThrow() or expectAsync.teBeRejectedWith().

mtrezza avatar Apr 07 '22 10:04 mtrezza

@mtrezza can you check the test again?

Meglali20 avatar Apr 07 '22 16:04 Meglali20

@Meglali20 It seems the tests are still failing...

mtrezza avatar Apr 11 '22 20:04 mtrezza

@mtrezza what do you mean by failing? Do you mean the test fails to run? because for me the test runs and shows that its fails and if I change it so that it passes I get no issue

Meglali20 avatar Apr 12 '22 14:04 Meglali20

If you take a look at the tests here, you can see that 16 of them are failing.

mtrezza avatar Apr 13 '22 07:04 mtrezza

@mtrezza when I opened the issue and explained it you asked me for a failing test, the test is provided, and when I run npm test spec/ParseUser.spec.js from my side all the test passes except the one that I added fails as intended, also here on GitHub I can see that it fails and that there are some that are still pending. I really didn't get what is the issue, can you please explain it to me? I also just changed _logInWith to logInWith

Meglali20 avatar Apr 13 '22 11:04 Meglali20

Thanks for simplifying the test, it looks good to me. Do you have a suggestion for a fix?

mtrezza avatar Apr 25 '22 19:04 mtrezza

Unfortunately, I have no idea about it since it hasn't been long since I discovered and started using parse so I am not completely familiar with it and didn't look at the code yet. There could be some workaround to avoid this issue but that would be just adding unnecessary extra data to the database. you should be updating the label of the issue so that maybe someone can take a look at it and propose a solution.

Meglali20 avatar Apr 26 '22 14:04 Meglali20

@mtrezza any update?

Meglali20 avatar Jun 05 '22 23:06 Meglali20

@parse-community/server anyone has a suggestion for a fix? The failing test here already demos the issue.

mtrezza avatar Jun 06 '22 08:06 mtrezza

I would assume the issue is happening somewhere around here

https://github.com/parse-community/parse-server/blob/c1e808f9e807fc49508acbde0d8b3f2b901a1638/src/RestWrite.js#L1604

dblythy avatar Jun 06 '22 08:06 dblythy

@Meglali20 Would you want to rebase this PR on alpha and resolve the conflicts?

mtrezza avatar Jun 06 '22 16:06 mtrezza

@mtrezza you mean if I could fix it? I didn't have time yet to look at the parse server code, so I don't think I could fix it at the moment, If you could provide me with some information on how the process works I would maybe try to figure it out.

Meglali20 avatar Jun 08 '22 23:06 Meglali20

@Meglali20 I didn't mean to fix the issue, just to fix the conflicts in this PR: image

There have been commits to alpha since you opened this PR, so there are some conflicts between the latest code and this PR.

mtrezza avatar Jun 10 '22 12:06 mtrezza

Resolved conflicts.

Meglali20 avatar Jun 10 '22 12:06 Meglali20

Was there ever a fix for this? Or still just a test that showcases the bug?

JesperLekland avatar Jun 30 '23 12:06 JesperLekland

@JesperLekland I am not aware of any fix, I just used a workaround by creating a new class for already registered users.

Meglali20 avatar Jul 01 '23 16:07 Meglali20

I will reformat the title to use the proper commit message syntax.