MIPB
MIPB

Reputation: 2471

How to recover user account if user has deleted the app or changed phone?

I am working with Cloud Firestore and I came to the question on the top. I will set you an example

  1. The user installs the app and log's in with Google. I save the log-in information in the device storage so the user does not have to log in every time. It is also stored in Firestore with a generated ID.
  2. The user plays with the app and one day uninstalls it. This erases the log-in information in the async storage, losing the generated ID that granted him access to the app.
  3. One day he decides to install it again, let's say in another device to make it harder. He had various information in his profile or maybe an active payment plan he forgot to delete and he wants to do it now. He clicks on google log in since it was how he did it, but now the profile information is gone because another account was created with another generated ID.

How to avoid this? I want the app to remember the user account in some way. The user account would be stored in my Firestore.

Upvotes: 0

Views: 879

Answers (2)

Alex Mamo
Alex Mamo

Reputation: 138999

According to the docs:

  • For Android and iOS, offline persistence is enabled by default.

Meaning that by default, Firestore creates a locate copy of the database on the client's device.

User installs app and log's in with Google.

So I assume you have already implemented Firebase authentication with Google.

It is also stored in Firestore with a generated ID.

Without seeing that "generated ID", it's hard to say if it's the correct ID or not. The idea behind this authentication is to sign-in your users with Firebase, no matter what the provider is. Furthermore, if you want to save user data in Firestore, store it into a document whose id is the user ID that comes from the authentication process. In this way, doesn't matter what the provider is, you'll always store the data under a document whose key will never change.

User plays with the app and one day uninstalls it. This erases the log-in information in the async storage, losing the generated ID that granted him access to the app.

It's true that if the user uninstalls the app, all the cache is wiped out from the storage, including the log-in information. That being said, bear in mind that you should never store such information on the disk. When using Firebase authentication, there is no log-in information that needs to be stored. If you didn't still implement it, I recommend you start with the docs.

One day he decides to install it again, let's say in another device to make it harder. He had various information in his profile or maybe an active payment plan he forgot to delete and he wants to do it now. He clicks on google log in since it was how he did it, but now the profile information is gone because another account was created with another generated ID.

This is only happening if you are using a type of ID other than the one explained above. If you had used the ID that comes from the authentication process, the second time the user tries to sing-in, even if using a different device, he'll be recognized as the same user with the same data. In this way, the user will be able to access the same document with the same data and recreate the local cache.

Upvotes: 2

SempaiLeo
SempaiLeo

Reputation: 344

Im not sure in which framework you are working in to create the app, but firebase sdk has sign in along with create user with email & password. Needed data could be saved to user's document on Firestore.

Upvotes: 0

Related Questions