Short answer

To go straight from Google Sign-In to your home screen, with no way back to the login screen, replace the navigation stack instead of pushing: navigationController.setViewControllers([home], animated:). With the current Google Sign-In SDK (10.1.0) there's no delegate anymore: call signIn(withPresenting:completion:) from the button and restorePreviousSignIn at launch, then pick the screen from the result. The 2018 code used GIDSignInDelegate, uiDelegate and hasAuthInKeychain(), all removed. A test with a stand-in for the SDK shows the stack holding only one screen after each step.

SWIFT TIPS · LOGIN · GOOGLE SIGN-IN

First posted on April 13, 2018, as "Google SignIn Delegate Navigation to second viewController SWIFT 4". Rewritten on November 19, 2026. The SDK calls come from the public headers and changelog of Google Sign-In for iOS 10.1.0, read on November 19, 2026. The navigation code was compiled and run as a Mac Catalyst program with Swift 6.2.3 (Xcode 26.2, Swift 5 mode), with a small stand-in that copies the SDK's method signatures; the real SDK wasn't installed and no Google account was used.

In 2018 my problem was this: after tapping the Google button and signing in, the app came back to the first view controller, the login screen. I wanted it to continue to the second one. The fix in the post was in the GIDSignInDelegate method sign(_:didSignInFor:withError:): if GIDSignIn.sharedInstance().hasAuthInKeychain() was true, create the second view controller and call navigationController?.setViewControllers([vc], animated: true); otherwise dismiss. viewDidLoad set the delegates and called signInSilently().

The navigation part was right, and it's still the answer. The SDK part has changed completely since. This rewrite keeps the idea, moves it out of the login screen, and uses the current API.

Why setViewControllers is the right call

Pushing the home screen puts it on top of the login screen, so Back returns to login, and the login screen stays in memory. setViewControllers([home], animated: true) replaces the whole stack: home becomes the only screen, there's no Back button, and the login screen is released. The same call works the other way at logout.

What changed in the SDK

  • No delegates. GIDSignInDelegate and GIDSignInUIDelegate are gone. Sign-in takes a completion block: signIn(withPresenting:completion:), with a GIDSignInResult or an error.
  • Restoring a session. signInSilently() became restorePreviousSignIn(completion:), and hasAuthInKeychain() became hasPreviousSignIn(). The header says restorePreviousSignIn restores the user from the local cache and refreshes tokens if they're older than an hour.
  • When to call what. The header for signIn says not to call it when the app is starting up, and to use restorePreviousSignIn for that. The 2018 viewDidLoad is that startup moment.
  • Installation. The 10.1.0 changelog says it's the last release published to CocoaPods, which becomes read-only on December 2, 2026, and points to Swift Package Manager. The package declares iOS 15 as its minimum.

The setup itself, the client ID and the URL scheme, is in the Google Sign-In setup post linked below.

One object decides the first screen

In 2018 the login screen did the navigation itself, which meant it had to know about the next screen and had to be the delegate. A small flow object owns the navigation controller and decides; the login screen only reports that sign-in worked:

import UIKit
import GoogleSignIn

/// Decides which screen is the root: login or home. Login never stays under home.
final class AuthFlow {
    private let navigation: UINavigationController
    private let makeLogin: () -> LoginViewController
    private let makeHome: () -> UIViewController

    init(navigation: UINavigationController,
         makeLogin: @escaping () -> LoginViewController,
         makeHome: @escaping () -> UIViewController) {
        self.navigation = navigation
        self.makeLogin = makeLogin
        self.makeHome = makeHome
    }

    /// Call once at launch.
    func start() {
        guard GIDSignIn.sharedInstance.hasPreviousSignIn() else { showLogin(); return }
        GIDSignIn.sharedInstance.restorePreviousSignIn { [weak self] user, _ in
            user == nil ? self?.showLogin() : self?.showHome()
        }
    }

    func showLogin() {
        let login = makeLogin()
        login.onSignedIn = { [weak self] _ in self?.showHome() }
        replaceStack(with: login)
    }

    func showHome() { replaceStack(with: makeHome()) }

    func signOut() {
        GIDSignIn.sharedInstance.signOut()
        showLogin()
    }

    private func replaceStack(with root: UIViewController) {
        // Animate only when the navigation controller is on screen.
        navigation.setViewControllers([root], animated: navigation.viewIfLoaded?.window != nil)
    }
}

The login screen calls signIn(withPresenting:) and, on success, calls onSignedIn, which the flow set:

import UIKit
import GoogleSignIn

final class LoginViewController: UIViewController {
    var onSignedIn: ((GIDGoogleUser) -> Void)?

    @IBAction private func googleTapped(_ sender: UIButton) {
        GIDSignIn.sharedInstance.signIn(withPresenting: self) { [weak self] result, error in
            if let error = error {
                print("Google sign-in failed:", error.localizedDescription)  // includes the user cancelling
                return
            }
            guard let user = result?.user else { return }
            // Send this to your server and verify it there; don't trust it on the device alone.
            let idToken = user.idToken?.tokenString
            print("Signed in:", user.profile?.email ?? "-", "| has ID token:", idToken != nil)
            self?.onSignedIn?(user)
        }
    }
}

At launch, the scene delegate creates the navigation controller, makes it the window's root, creates AuthFlow with closures that build the login and home screens, and calls start(). Keep a reference to the flow, for example as a property of the scene delegate, so it lives as long as the window.

What the test showed

I ran the flow and the login screen with a stand-in for GIDSignIn whose saved state I could switch, and printed the navigation stack after each step:

launch, no saved sign-in      -> stack: LoginViewController
sign-in finished               -> stack: HomeViewController | back button possible: false
sign out                       -> stack: LoginViewController | saved sign-in: false
launch, saved sign-in restored -> stack: HomeViewController
  • After sign-in, only home is on the stack. No Back button, and the login screen is gone.
  • Sign-out goes back to a fresh login screen, again as the only screen.
  • A saved sign-in skips login entirely. At launch, hasPreviousSignIn() was true and restorePreviousSignIn returned a user, so home was the first screen shown.

The flow animates only when the navigation controller is in a window. In an earlier test of the same pattern, an animated setViewControllers on a controller with no window didn't apply, so the code checks viewIfLoaded?.window first.

Leftovers from the 2018 code

  • Facebook code in a Google screen. The 2018 viewDidLoad also checked FBSDKAccessToken.current(). When a screen offers several logins, each one can report to the same flow object instead of the screen checking every provider.
  • var user = GIDSignIn() created a second sign-in object that was never used. Only GIDSignIn.sharedInstance is needed; the current header marks init as unavailable.
  • Dismissing on failure. The 2018 code called dismiss when sign-in failed, which closes the login screen itself if it was presented. On failure, stay on the login screen and show the error, unless the person cancelled.

A quick check for your project

  1. Search for GIDSignInDelegate, signInSilently and hasAuthInKeychain. Any match means the code uses an SDK from before version 6.
  2. Sign in, then try the Back gesture. If login reappears, the code pushed instead of replacing the stack.
  3. Kill the app after signing in and open it again: it should open on home without showing login.

What the 2018 version said

The post was text and code only. It ended with "This my note as my problem and solution" and a LinkedIn handle, which I left out.

Sources