step-up-labs / firebase-authentication-dotnet

C# library for Firebase Authentication
MIT License
376 stars 129 forks source link

How to persist authentication across app restarts ? #210

Open cagriy opened 10 months ago

cagriy commented 10 months ago

Hello, I am new to Firebase Auth, excuse if I was missing something obvious.

When I run

var userCredential = await client.CreateUserWithEmailAndPasswordAsync("email", "pwd", "Display Name");

It successfully returns a UserCredential object with Id Token and Refresh Token in it.

What would be the correct approach to persist signin across app sessions (including restarts) ? Reading about Id and Refresh tokens I think the idea is saving the refresh token to generate a new Id token on the next session however GetTokenAsync method is part of UserCredentials object and it is a quite complex one to re-populate the object.

Reading Firebase Auth documentation there is a section about persistence however I am not clear how this package implements it if at all.

How can I make sure that the user is still signed it after the app is restarted and how can I get a fresh Id Token ?

Many thanks,

Cagri

bezysoftware commented 10 months ago

Hi, see the readme https://github.com/step-up-labs/firebase-authentication-dotnet#firebaseauthenticationnet-1 Persistence is implemented via UserRepository. You can also explore sample projects in this repo

cagriy commented 10 months ago

Hi @bezysoftware , thanks a lot for the quick response.

I got it, I need to use UserRepository definition so that the signin information is persisted. And when I come back client.User object is maintained :)

One last question if I may:

What would be the right way to refresh the persisted authentication information ?

I create an account, check User.IsEmailVerified, it is false. I close the app, verify email and re-open the app, it still shows as false.

There is a mention to User.Reload() method but this doesn't seem to be available in my case.

Thanks

RaJansuMan commented 8 months ago

okay but how do you use this to refresh the token ?

RaJansuMan commented 8 months ago

found it .. readme.md should be updated to include for beginners

bezysoftware commented 8 months ago

Feel free to send a PR to update the readme.

bezysoftware commented 8 months ago

Hi @bezysoftware , thanks a lot for the quick response.

I got it, I need to use UserRepository definition so that the signin information is persisted. And when I come back client.User object is maintained :)

One last question if I may:

What would be the right way to refresh the persisted authentication information ?

I create an account, check User.IsEmailVerified, it is false. I close the app, verify email and re-open the app, it still shows as false.

There is a mention to User.Reload() method but this doesn't seem to be available in my case.

Thanks

I think refreshing the user information isn't implemented right now