Skip to content

Commit 9edb9ac

Browse files
authored
Remove firebaseToken from persistence if tokenRefreshHandler is not s… (#9298)
* Remove firebaseToken from persistence if tokenRefreshHandler is not set and token is expired * Update to call signOut instead * update comment * minnor changes
1 parent 7e14a59 commit 9edb9ac

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/auth/src/core/auth/auth_impl.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ describe('core/auth/auth_impl', () => {
367367
const token = await auth.getFirebaseAccessToken();
368368
expect(token).to.be.null;
369369
expect(exchangeTokenStub).not.to.have.been.called;
370+
expect(persistenceStub._remove).to.have.been.called;
370371
});
371372

372373
it('should refresh the token if token is expiring in next 1 minute and a token refresh handler is set', async () => {
@@ -442,6 +443,7 @@ describe('core/auth/auth_impl', () => {
442443
'Token refresh failed:',
443444
sinon.match.instanceOf(Error)
444445
);
446+
expect(persistenceStub._remove).to.have.been.called;
445447
});
446448

447449
it('should return null and log an error if the refreshed token is invalid', async () => {

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
267267
}
268268

269269
if (firebaseAccessToken && this.tokenRefreshHandler) {
270-
// Resets the Firebase Access Token to null i.e. logs out the user.
271-
await this._updateFirebaseToken(null);
272270
try {
273271
// Awaits for the callback method to execute. The callback method
274272
// is responsible for performing the exchangeToken(auth, valid3pIdpToken)
@@ -282,9 +280,10 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
282280
return this.getFirebaseAccessToken(false);
283281
} catch (error) {
284282
console.error('Token refresh failed:', error);
285-
return null;
286283
}
287284
}
285+
// Signs out the user i.e. sets the firebaseToken to null if firebase token is not valid and refresh token handler is not set/ successful.
286+
await this.signOut();
288287
return null;
289288
}
290289

0 commit comments

Comments
 (0)