firebase-authentication-dotnet icon indicating copy to clipboard operation
firebase-authentication-dotnet copied to clipboard

How to persist authentication across app restarts ?

Open cagriy opened this issue 2 years ago • 6 comments

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

cagriy avatar Nov 16 '23 17:11 cagriy

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

bezysoftware avatar Nov 16 '23 19:11 bezysoftware

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

cagriy avatar Nov 17 '23 17:11 cagriy

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

RaJansuMan avatar Jan 10 '24 06:01 RaJansuMan

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

RaJansuMan avatar Jan 10 '24 09:01 RaJansuMan

Feel free to send a PR to update the readme.

bezysoftware avatar Jan 12 '24 11:01 bezysoftware

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

bezysoftware avatar Jan 12 '24 11:01 bezysoftware