I'm using firebase to build a browser based app. I'm having this piece of code that is called when the page loads,
this._app = initializeApp({
apiKey: this._apiKey,
authDomain: `${this._projectId}.firebaseapp.com`,
projectId: this._projectId,
storageBucket: `${this._projectId}.appspot.com`,
messagingSenderId: this._senderId,
appId: this._appId
});
this._db = getFirestore(this._app);
Then I've a login method that uses browserLocalPersistence as below,
async login(email, password) {
const auth = getAuth();
await setPersistence(auth, browserLocalPersistence);
return signInWithEmailAndPassword(auth, email, password);
}
When I login first I see the token is successfully stored in localstorage. On refreshing the page I see the token is removed from localstorage and I think this is happening due to initializeApp. How can I keep the token persistent in localstorage?