[iOS] Lock.swift User is Signed Out after a Couple Days

Currently our app is using Lock.swift (which uses Auth0 Swift v1.39.1 as its dependency) to support Auth0 login natively. Not able to figure out why accounts are signed out after 24-48 hours and are required to login again. I was able to figure out it has to do with the refreshToken logic with Auth0 returning the error 0. Below is sample code of the Auth0 token refresh:

private let group = DispatchGroup()
func refreshTokenIfNeeded() {
        /// Credential retrieval is queued asynchronously on background thread
        /// while using DispatchGroup to lock execution to a single thread at a time
        group.enter()

        DispatchQueue.global().async { [weak self] in
            self?.credentialsManager.credentials(withScope: "openid profile email offline_access",
                                                 parameters: [
                                                    "isMobile": "true",
                                                   "regsource": "****", // hidden
                                                   "prompt": "login"
                                                   ]) { error, credentials in
                if let credentials = credentials,
                   let tokenExpDate = credentials.expiresIn {
                    self?.saveTokenExpirationDate(tokenExpDate)
                } else {
                    Logger("Auth0 fetch error: \(String(describing: error?.localizedDescription))")
                }

                /// Completion is returned via main thread, allowing UI
                /// to perform necessary updates to handle completion handler response
                DispatchQueue.main.async {
                    completion(error, credentials)
                }

                self.group.leave()
            }
        }

        group.wait()
}

I was able to eliminate threads being the culprit here after following the flow of breakpoints manually on my end for several hours. It’s specifically the bearer token not refreshing that’s causing the issue. Since the bearer token fails to refresh, it will trigger a sign out flow then prompt the user to sign into their account. Any help on this would be appreciated to prevent more of our users from experiencing this logout issue. Thanks in advance.

Hi @pridefulswiftdev

Thanks for getting in touch with us at Auth0 Community.

A few of things I would check:

Perhaps download a vanilla version of our IOS Quickstart from https://auth0.com/docs/quickstart/native/ios-swift and see if you can replicate the issue once it’s configured to use Lock.Swift, if so then please log an issue in our GitHub repo here https://github.com/auth0/Auth0.swift/issues as then the SDK maintainers will be able to review using your sample.

Warm regards.