From f88bf552affe1b7f830fe4106c102ed90bbcd1f3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 23 Jan 2023 17:43:41 -0500 Subject: [PATCH] Reuse client ID/secret when trying to sign in to the same account again Workaround for mastodon.social signins being flaky --- .../Onboarding/OnboardingViewController.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Tusker/Screens/Onboarding/OnboardingViewController.swift b/Tusker/Screens/Onboarding/OnboardingViewController.swift index c3c4208a..980553d1 100644 --- a/Tusker/Screens/Onboarding/OnboardingViewController.swift +++ b/Tusker/Screens/Onboarding/OnboardingViewController.swift @@ -23,6 +23,8 @@ class OnboardingViewController: UINavigationController { var authenticationSession: ASWebAuthenticationSession? + private var clientInfo: (url: URL, id: String, secret: String)? + init() { super.init(rootViewController: instanceSelector) } @@ -42,10 +44,16 @@ class OnboardingViewController: UINavigationController { let mastodonController = MastodonController(instanceURL: instanceURL, transient: true) let clientID: String let clientSecret: String - do { - (clientID, clientSecret) = try await mastodonController.registerApp() - } catch { - throw Error.registeringApp(error) + if let clientInfo, clientInfo.url == instanceURL { + clientID = clientInfo.id + clientSecret = clientInfo.secret + } else { + do { + (clientID, clientSecret) = try await mastodonController.registerApp() + self.clientInfo = (instanceURL, clientID, clientSecret) + } catch { + throw Error.registeringApp(error) + } } let authCode = try await getAuthorizationCode(instanceURL: instanceURL, clientID: clientID) let accessToken: String