Unable to consistently login with auth0 on ios in swiftui

Hello,

I have a swiftui app targeting ios 17+ using Auth0 package 2.1.0. Unfortunately, 90% of the time my app is rejected from the app store because when the tester clicks on the login button or create account button nothing happens because there is an error. If they wait 3-5 seconds before clicking it (or click it again after 3-5 seconds) will generally work but it is inconsistent. The error in the console is this:

An unexpected error occurred. CAUSE: Error Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=1 “Application with identifier xxxxxxxxx is not associated with domain yyyyyyyy. Using HTTPS callbacks requires Associated Domains using the webcredentials service type for yyyyyyyy.” UserInfo={NSLocalizedFailureReason=Application with identifier xxxxxxxx is not associated with domain yyyyyyyy. Using HTTPS callbacks requires Associated Domains using the webcredentials service type for yyyyyyyyyyy.}

I can assure you that overall I have no issues with this on my and my testers devices, in test flight, xcode, on real devices and simulators but for some reason at start up, this error sometimes happens and it nearly always happens for testers and I don’t know what to do about it.

How can I resolve this? Any help anyone can provide would be absolutely amazing!

Here is my swiftui code that is triggered on button click:

@MainActor
    func fallbackToAuth0Login(loginScreen: Bool = true) {
        
        if let aud = Bundle.main.infoDictionary?["AUTH0_AUDIENCE"] as? String {
            Auth0
                .webAuth()
                .useHTTPS()
                .parameters(["screen_hint": loginScreen ? "login" : "signup"])
                .audience(aud)
                .scope("openid profile email offline_access")
                .start { result in
                    switch result {
                    case .success(let credentials):
                        completeLogin(creds: credentials)
                    case .failure(let error):
                        print("Login Failed with: \(error)")
                    }
                }
        }
    }```

Hi @taylorgt

Welcome to the Auth0 Community!

Thank you for posting your issue with Apple verification. We know this issue, and our team is working on a solution. I will update you once I have more information regarding this issue.

Thanks
Dawid

hi there! Glad to find this update as well because login/create account failed. I just had my app rejected by the store as well. Can you let me know once it’s resolved as well?

1 Like

Hey @paulatgfx, fwiw, this was my work around. Basically, I listened for the error and tried again until it worked, which typically is less than an additional second if it even happens. Here is the code I used, I hope it helps:

func fallbackToAuth0Login(loginScreen: Bool = true) {
    let loadingView = UIView(frame: UIScreen.main.bounds)
    loadingView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
    let spinner = UIActivityIndicatorView(style: .large)
    spinner.color = .white
    spinner.center = loadingView.center
    spinner.startAnimating()
    loadingView.addSubview(spinner)
    
    let startTime = Date()
    
    func tryAuth() {
        if let aud = Bundle.main.infoDictionary?["AUTH0_AUDIENCE"] as? String {
            Auth0
                .webAuth()
                .useHTTPS()
                .parameters(["screen_hint": loginScreen ? "login" : "signup"])
                .audience(aud)
                .scope("openid profile email offline_access")
                .start { result in
                    switch result {
                    case .success(let credentials):
                        loadingView.removeFromSuperview()
                        completeLogin(creds: credentials)
                    case .failure(let error):
                        print("Login Failed with: \(error)")
                        
                        if error.localizedDescription.contains("not associated with domain") &&
                           Date().timeIntervalSince(startTime) < 10 {
                            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                                tryAuth()
                            }
                        } else {
                            loadingView.removeFromSuperview()
                        }
                    }
                }
        }
    }
    
    if let window = UIApplication.shared.windows.first {
        window.addSubview(loadingView)
    }
    tryAuth()
}
1 Like

@taylorgt brilliant, thank you for this. I’ll give it a shot.

I put in the retry mechanism and the app was rejected again. I see the logs from the review session where it retried once every .5 seconds for 10 seconds and wasn’t successful. So still am very interested in a solution.