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

How to handle network errors in the middle of createUser flow? #503

Open
compojoom opened this issue Jul 6, 2018 · 4 comments
Open

How to handle network errors in the middle of createUser flow? #503

compojoom opened this issue Jul 6, 2018 · 4 comments

Comments

@compojoom
Copy link
Contributor

I was greeted today by a bug report. The report was saying - user can't create anything.
I looked into the authentication page on firebase and grabbed the user's id. Then I went in firestore and tried to look his profile in the database - it was missing... That's impossible I thought - when we create a user, we have a profileFactory and it is responsible for writing to firestore. We save the email, uid, name etc in firestore.

Then I looked at our code and in the code of redux-firebase and realized that the only way this to happen is for the internet connection to be interrupted in the exact moment after logging in the user.
I tried to reproduce this and it turned out that I was correct.
here are the actions
grafik
I managed to cut out the internet connection right after firebase/LOGIN, then SET_PROFILE fails with unauthorized_error. The actual error code there is firestore/unavailable.

Any ideas how to recover from this (other than to have a stable internet connection :))?

is there an easy way around this problem? Right now what I am thinking about is giving up using createUser and writing a cloud function that receives all the data needed to register the user. Once the user is registered on the server, I can copy his data to the users collection & then I'll return a success to the app and the app could try to login with the email and password the user provided.

@prescottprue
Copy link
Owner

Hmmm interesting problem. Was there anything within the auth tab for that user (I.e. they were created, but there profile was not)?

Your proposed solution does seems like a great approach for now, but it would be nice to figure out a way to handle it on the client.

In theory you could catch the unsuccessful createUser call and if it is that specific error then first check for auth - if it exists, the user is logged in, but didn't create profile, so you can use updateProfile with their auth data. If Auth doesn't exist, then you can try logging in.

In the longer term, this should probably be handled within react-redux-firebase, but we will have to come up with a of making that work.

@compojoom
Copy link
Contributor Author

compojoom commented Jul 6, 2018

as a short term solution I implemented an onCreate function that copies the uid and email (it seems that this has happened to 0.5% of our users). This way even if the copy of the profile fails the user can continue to use the app.

I want to test the following though.

The .catch is catching the error on the .get() so we never actually come to the part that is responsible for updating the profile. If we change the .get() to onSnapshot, then we shouldn't get this error? And once we end up in .then() we could unsubscribe to onSnaptshot and execute our code further. Not sure if this will work - need to test it.

@prescottprue
Copy link
Owner

@compojoom Love the idea! Let me know if you end up testing it out. As always, I'm open to a PR

@compojoom
Copy link
Contributor Author

working on something else, but once I get some free time I'll test whether this works or not and create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants