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 persist authentication across app restarts ? #210

Open
cagriy opened this issue Nov 16, 2023 · 6 comments
Open

How to persist authentication across app restarts ? #210

cagriy opened this issue Nov 16, 2023 · 6 comments
Labels

Comments

@cagriy
Copy link

cagriy commented Nov 16, 2023

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
Copy link
Collaborator

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
Copy link
Author

cagriy commented Nov 17, 2023

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
Copy link

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

@RaJansuMan
Copy link

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

@bezysoftware
Copy link
Collaborator

Feel free to send a PR to update the readme.

@bezysoftware
Copy link
Collaborator

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

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

No branches or pull requests

3 participants