diff --git a/Tusker/Screens/Onboarding/OnboardingViewController.swift b/Tusker/Screens/Onboarding/OnboardingViewController.swift index b94a9a4cde..fe13b67dd9 100644 --- a/Tusker/Screens/Onboarding/OnboardingViewController.swift +++ b/Tusker/Screens/Onboarding/OnboardingViewController.swift @@ -68,13 +68,16 @@ extension OnboardingViewController: InstanceSelectorTableViewControllerDelegate let authCode = item.value else { return } mastodonController.authorize(authorizationCode: authCode) { (accessToken) in - let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: nil, accessToken: accessToken) - mastodonController.accountInfo = accountInfo + // construct a temporary UserAccountInfo instance for the MastodonController to use to fetch it's own account + let tempAccountInfo = LocalData.UserAccountInfo(id: "temp", instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: nil, accessToken: accessToken) + mastodonController.accountInfo = tempAccountInfo mastodonController.getOwnAccount { (account) in - LocalData.shared.setUsername(for: accountInfo, username: account.username) - DispatchQueue.main.async { + // this needs to happen on the main thread because it publishes a new value for the ObservableObject + let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: account.username, accessToken: accessToken) + mastodonController.accountInfo = accountInfo + self.onboardingDelegate?.didFinishOnboarding(account: accountInfo) } }