# Unable to consistently login with auth0 on ios in swiftui

**URL:** <https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [December 12, 2024, 3:48am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662 "2024-12-12T03:48:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorgt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taylorgt/32/65019_2.png) [@taylorgt](https://community.auth0.com/u/taylorgt)\
**Post date:** [December 12, 2024, 3:48am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/1 "2024-12-12T03:48:02Z")

</div>

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:

````auto
@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)")
                    }
                }
        }
    }```
````

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [December 30, 2024, 10:30pm UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/3 "2024-12-30T22:30:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulatgfx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paulatgfx/32/70457_2.png) [@paulatgfx](https://community.auth0.com/u/paulatgfx)\
**Post date:** [January 13, 2025, 6:45pm UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/4 "2025-01-13T18:45:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![taylorgt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/taylorgt/32/65019_2.png) [@taylorgt](https://community.auth0.com/u/taylorgt)\
**Post date:** [January 14, 2025, 1:03am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/5 "2025-01-14T01:03:02Z")

</div>

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:

```auto
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()
}

```

---

<div class="post-metadata">

**Author:** ![paulatgfx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paulatgfx/32/70457_2.png) [@paulatgfx](https://community.auth0.com/u/paulatgfx)\
**Post date:** [January 14, 2025, 9:26pm UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/6 "2025-01-14T21:26:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulatgfx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paulatgfx/32/70457_2.png) [@paulatgfx](https://community.auth0.com/u/paulatgfx)\
**Post date:** [January 18, 2025, 12:10am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/7 "2025-01-18T00:10:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 1, 2025, 12:11am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/8 "2025-02-01T00:11:14Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [February 20, 2025, 1:55am UTC](https://community.auth0.com/t/unable-to-consistently-login-with-auth0-on-ios-in-swiftui/161662/9 "2025-02-20T01:55:25Z")

</div>

Hi there!

The solution to this question was shared in this post → [iOS Application not recognizing Auth0 Associated Domain - #27 by marybeth.hunter](https://community.auth0.com/t/ios-application-not-recognizing-auth0-associated-domain/134847/27)

Thanks  
Dawid
