Search code examples
firebasedelphigoogle-cloud-firestorefiremonkey

Firestore reauthenticate user


I'm using Delphi 10.4.2 and FB4D to do a mobile app.

The first time the user open the app, he create an account (mail / password).

Then he can call Firebase to get documents where he is the owner (settings Firestore rules).

The user can close the app.

When he open it, I didn't want ask him for the password, and I didn't want to store the password on a config file to login him.

I prefer to store a token, and then ask for refresh when it is expired.

When a user is login, I can refresh token like that :

if fAuth.NeedTokenRefresh then
   fAuth.RefreshToken(OnTokenRefresh, onUserError);

The problem is that the second time he open the app, FAuth isn't initialized. Unless I store mail / pwd and login user, what I didn't want to do.

Does it's possible ?


Solution

  • If someone have same question, you can login a user with the last refresh token you get :

    FraSelfRegistration.Initialize(FConfig.Auth, OnUserLogin, 'last_token');
    

    You need to add the uses FB4D.SelfRegistrationFra and init FConfig like that :

    FConfig := TFirebaseConfiguration.Create(ApiKey, ProjectID, '', FirebaseURL);
    

    So you can login user without store any password