My authentication process relies on two key factors:
- Using Firebase auth (email and password)
- Making a server API call to retrieve the complete customer entity from the database based on the firebaseID. The user must exist in both places for successful authentication.
I have implemented authGuards that are based on an isAuthenticated()
function returning an Observable. This is necessary because during page refreshes, the guard needs to wait for the authentication process to finish before redirecting the user.
The issue I am facing is with managing all the asynchronous calls and RxJS operations. Currently, the serverAPI auth is called every time the isAuthenticated
function is invoked. How can I refactor this to ensure that the server call is made only once while still maintaining the async behavior and handling reloads effectively?
AuthService :
paste here AuthService code...
AuthGuard :
paste here AuthGuard code...
Thank you