fix(auth): clear provider sessions on sign-out without linking the Facebook SDK - #2499
fix(auth): clear provider sessions on sign-out without linking the Facebook SDK#2499demolaf wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the sign-out flow in FirebaseAuthUI to ensure that provider-side sessions (Google and Facebook) are cleared properly. Since auth.signOut() clears the current user, the linked providers are now captured from providerData beforehand. Additionally, the Facebook sign-out logic is guarded to handle cases where the Facebook SDK is not present at runtime. Feedback on these changes suggests avoiding catching Throwable in signOutFromFacebook to prevent swallowing critical JVM errors, recommending catching LinkageError and Exception separately instead.
| try { | ||
| if (Provider.fromId(auth.currentUser?.providerId) != Provider.FACEBOOK) return | ||
| loginManagerProvider.logOut() | ||
| } catch (e: Exception) { | ||
| } catch (e: Throwable) { | ||
| Log.e("FacebookAuthProvider", "Error during Facebook sign out", e) | ||
| } |
There was a problem hiding this comment.
Catching Throwable is generally discouraged as it swallows critical JVM errors such as OutOfMemoryError, StackOverflowError, or ThreadDeath. Since the Facebook SDK is a compileOnly dependency, missing classes will throw a NoClassDefFoundError (which extends LinkageError). Catching LinkageError and Exception separately allows you to safely handle both the missing SDK scenario and any runtime exceptions without swallowing critical system errors.
try {
loginManagerProvider.logOut()
} catch (e: LinkageError) {
Log.e("FacebookAuthProvider", "Facebook SDK not available or mismatched", e)
} catch (e: Exception) {
Log.e("FacebookAuthProvider", "Error during Facebook sign out", e)
}There was a problem hiding this comment.
Done, narrowed to LinkageError plus Exception. That covers both compileOnly failure modes (absent SDK, version mismatch) without swallowing OutOfMemoryError and friends.
bca0e64 to
2404066
Compare
FirebaseAuthUI.signOut()never cleared the provider-side session. Both provider logout helpers ran afterauth.signOut()had already clearedcurrentUser, and their guard testedFirebaseUser.providerId, which the SDK always reports as"firebase", so neither ever executed. A Google user's saved credential state survived sign-out, silently re-selecting the same account on the next sign-in instead of showing the picker, and a Facebook user was never logged out.signOut()now reads the linked providers fromproviderDatabefore signing out of Firebase, then clears each provider's session from the call site. The Facebook branch is additionally gated onProviderAvailability.IS_FACEBOOK_AVAILABLE, sincefacebook-loginiscompileOnlyandproviderDatacan carryfacebook.comfor an account linked on another platform. Both helpers lose their now-unreachable internal guard and unusedauthparameter;signOutFromGooglerethrowsCancellationExceptioninstead of swallowing it.Added two
FirebaseAuthUITestcases and the first e2e coverage ofFirebaseAuthUI.signOut(), verified to fail on the old code and pass with the fix. Three pre-existing tests stubbedmockUser.providerIdto values the real SDK never returns, which is what hid the bug; those stubs are gone.Maintainer note: Fixes internal CPRN-435