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

Firebase Auth - Signing users out after 30 minutes (As of Xcode 13, iOS 15 SDK). #8695

Closed
cvcoder1 opened this issue Sep 23, 2021 · 23 comments · Fixed by #9622
Closed

Firebase Auth - Signing users out after 30 minutes (As of Xcode 13, iOS 15 SDK). #8695

cvcoder1 opened this issue Sep 23, 2021 · 23 comments · Fixed by #9622

Comments

@cvcoder1
Copy link

cvcoder1 commented Sep 23, 2021

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 13.0
  • Firebase SDK version: 8.7.0
  • Installation method: CocoaPods
  • Firebase Component: Auth/Core

(Added by me):

  • iOS Version: 15.0

[REQUIRED] Step 2: Describe the problem

After about 30 min., users are being signed out by Firebase automatically. This behavior did not occur prior to iOS 15. My company has in place, multiple safeguards via the iOS SDK & Cloud Functions for Auth. This issue is only occurring as of iOS 15.0.

Steps to reproduce:

Tested on both phone auth & Sign in with Apple:

Test 1:
Sign in --> Terminate application -> Open app after 5 minutes --> still logged in.

Test 2:
Sign in --> Terminate application -> Open app after 25 minutes --> still logged in.

Test 3:
Sign in -> Terminate application --> Open app after 31 minutes --> logged out of firebase.

What happened? How can we make the problem occur?

This just started happening as of iOS 15 & Xcode 13.
We have tests in place in our development environment to ensure things like this are not our fault.
And, our application in the store is not experiencing this behavior.

Relevant Code:

N/A.

@ryanwilson
Copy link
Member

Thanks for the report and sorry for the troubles. Does this happen in debug builds as well as release builds? Any extra steps or details you can share would be helpful as we try to reproduce this.

Are any logs produced in the console? We do log a few errors if the SDK has trouble loading the user. Stepping through this code would help as well:

// Load current user from Keychain.
FIRAuth *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
NSString *keychainServiceName =
[FIRAuth keychainServiceNameForAppName:strongSelf->_firebaseAppName];
if (keychainServiceName) {
strongSelf->_keychainServices =
[[FIRAuthKeychainServices alloc] initWithService:keychainServiceName];
strongSelf.storedUserManager =
[[FIRAuthStoredUserManager alloc] initWithServiceName:keychainServiceName];
}
NSError *error;
NSString *storedUserAccessGroup =
[strongSelf.storedUserManager getStoredUserAccessGroupWithError:&error];
if (!error) {
if (!storedUserAccessGroup) {
FIRUser *user;
if ([strongSelf getUser:&user error:&error]) {
strongSelf.tenantID = user.tenantID;
[strongSelf updateCurrentUser:user byForce:NO savingToDisk:NO error:&error];
self->_lastNotifiedUserToken = user.rawAccessToken;
} else {
FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
@"Error loading saved user when starting up: %@", error);
}
} else {
[strongSelf internalUseUserAccessGroup:storedUserAccessGroup error:&error];
if (error) {
FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
@"Error loading saved user when starting up: %@", error);
}
}
} else {
FIRLogError(kFIRLoggerAuth, @"I-AUT000001",
@"Error loading saved user when starting up: %@", error);
}

@rshubbard
Copy link

We are seeing the same issue with our App. Only iOS 15.

Xcode version: 12.5
Firebase SDK version: 8.7.0
Installation method: CocoaPods
Firebase Component: Auth/Core
iOS: 15

@ryanwilson
Copy link
Member

@rshubbard sorry for the troubles, can you please try the above steps and share any logs / step through the debugger in the code I linked above to try to reproduce this?

We have a couple people trying to reproduce this but currently we're unable to. We're hoping we can catch this and get it fixed ASAP for folks so any repro would be very helpful!

@rshubbard
Copy link

I have been unable to reproduce it in a debuggable state. We are only able to reproduce on 2 devices. On an iPhone 12 running iOS 15 I can reproduce 90% of the time if I shut down and power up the device. On older device running iOS 15, we can reproduce it if we wait an hour but also task it with other apps while it is backgrounded. The issue is definitely getting reported by our users as they are upgrading to iOS 15.

@ryanwilson
Copy link
Member

@rshubbard @cvcoder1 can you please share which function you're calling FirebaseApp.configure()? In an AppDelegate's applicationDidFinishLaunching call, SwiftUI lifecycle's init() function, somewhere else?

This forum post looks like it could be relevant, and that the keychain data and user defaults aren't available very early on in an app's lifecycle (presumably from cold start).

@cvcoder1
Copy link
Author

@ryanwilson nothing related to the forum post on our end. However, I just noticed we were calling FirebaseAppCheck prior to FirebaseApp.configure(). Could this be the cause?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    let providerFactory = MyAppCheckProviderFactory()
    AppCheck.setAppCheckProviderFactory(providerFactory)

    FirebaseApp.configure()

    return true
}

@cvcoder1
Copy link
Author

cvcoder1 commented Sep 25, 2021

We'll push a version to App Store Connect and test there as well.

This occurs when following my test procedure above, (after) building in Xcode on device, then unplugging, terminating and starting up again.

@cvcoder1
Copy link
Author

Re-arranged the app check config to be after 'FirebaseApp.configure()' - same behavior still occurring... @ryanwilson

@rshubbard
Copy link

rshubbard commented Sep 27, 2021

FirebaseApp.configure

Hey Ryan, we are using React Native Firebase (https://rnfirebase.io/). Here is our code to initialize in ios/PlaymetricsMobile/AppDelegate.m:

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    [FIRApp configure];

@maksymmalyhin
Copy link
Contributor

@rshubbard @cvcoder1 Could you please share the device logs relevant to the app for the period of time when the issue is reproducible on your device? We expect to see messages like [Firebase/Auth][I-AUT000001] Error loading saved user when starting up: ... that should clarify the underlying reason of the issue.

Here is an example how you may get the logs using Xcode.

@rshubbard
Copy link

I don't see anything from Firebase/Auth but I did see this:

8.7.0 - [Firebase/Messaging][I-FCM023014] Error while reading embedded mobileprovision Error Domain=NSCocoaErrorDomain Code=260 "The file “embedded.mobileprovision” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/private/var/containers/Bundle/Application/3C9A250A-2DDA-4CF1-A9FF-D32C976D4009/PlayMetrics.app/embedded.mobileprovision, NSUnderlyingError=0x281b7cba0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

@rshubbard
Copy link

I also see:

Task .<1> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])

deleted <genp,acct=firebase_auth_1___FIRAPP_DEFAULT_firebase_user,svce=firebase_auth_1:...:ios:...,agrp=BT8MVHD5Q2.com.playmetrics.mcr,sync=0,musr=, |otherAttr,tomb=0,rowid=945,cdat=2021-09-27 16:15:58 +0000,mdat=2021-09-27 16:15:58 +0000,pdmn=cku,sha1=...

@cvcoder1 cvcoder1 reopened this Sep 27, 2021
@cvcoder1
Copy link
Author

cvcoder1 commented Sep 27, 2021

@rshubbard @cvcoder1 Could you please share the device logs relevant to the app for the period of time when the issue is reproducible on your device? We expect to see messages like [Firebase/Auth][I-AUT000001] Error loading saved user when starting up: ... that should clarify the underlying reason of the issue.

Here is an example how you may get the logs using Xcode.

Ok thanks. Will do shortly. Closing the issue was accident. Github should definitely prompt an 'are you sure' in case of house cats jumping on keyboard..

@cvcoder1
Copy link
Author

@rshubbard @cvcoder1 Could you please share the device logs relevant to the app for the period of time when the issue is reproducible on your device? We expect to see messages like [Firebase/Auth][I-AUT000001] Error loading saved user when starting up: ... that should clarify the underlying reason of the issue.

Here is an example how you may get the logs using Xcode.

Is 'BuddyBuilds' relevant other than the sample tutorial of how to get Xcode logs? Confused there..

@morganchen12
Copy link
Contributor

@cvcoder1 BuddyBuild is a testing service unrelated to Firebase. They happened to have an informative blog post on how to get logs from Xcode. You don't need to use BuddyBuild to be able to access logs from Xcode.

@rshubbard
Copy link

OK my issue seems to be the internet connection. On phone reset you can start the application before the network connection has been established so I am adding a check for that.

@maksymmalyhin
Copy link
Contributor

maksymmalyhin commented Sep 28, 2021

@rshubbard Thank you for the updates. We are still unsure what's the core reason of the issue.

Could you please share all log entries with "[Firebase/" in them for the app run when the issue occurs. Hopefully it will give us more information on the issue.

@rosalyntan
Copy link
Member

Hi folks, sorry that you're experiencing this issue! A few questions:

@cvcoder1 What iPhone versions have you been experiencing this on? In addition, is it only on a physical device or have you also been able to reproduce this on a simulator? And to clarify the behavior you're seeing, is it that the currentUser property is nil after 31 minutes?

@rshubbard You mentioned that one of the devices you reproduced this on was an iPhone 12, after restarting the device. Was this in addition to waiting the 31 minutes mentioned in the repro steps of the first comment, or do you see the user signed out without the wait time?

In addition, if either of you can share any device logs (specifically log entries prefixed with [Firebase/Auth]) or an MVCE, that would be super helpful as well!

To turn on debug logs:
In Xcode, select Product > Scheme > Edit scheme.
Select Run from the left menu, then select the Arguments tab.
In the Arguments Passed on Launch section, add -FIRDebugEnabled.

@google-oss-bot
Copy link

Hey @cvcoder1. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@cvcoder1 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@ryanwilson
Copy link
Member

Hey folks, it looks like this article gives some good information on what could be happening - iOS 15 tries to optimize things and pre-load apps before they launch, meaning the keychain read will fail.

I'll re-open this and discuss it with the Auth team since there are some potential workarounds or optimizations we could do to alleviate the issue. In particular, I'm thinking we should try to hook into the protectedDataDidBecomeAvailable API and re-read from the keychain if the user doesn't exist.

@ryanwilson ryanwilson reopened this Dec 1, 2021
@ryanwilson
Copy link
Member

Hey @rosalyntan, do you think the potential workaround is reasonable, or any other thoughts on how we could mitigate this?

@alejandromaju
Copy link

Hey folks, any update about this fix?

@firebase firebase locked and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants