© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•6mo ago•
1 reply
Subin

Failed to start session: pkce(Auth.AuthError.PKCEFailureReason.invalidPKCEFlowURL)

I am getting an invalidPKCEFlowURL error when trying to login via Google from an iOS app. I am using SwiftUI.

I have verified the following things from my end
- Added the callback url in Google cloud console.
- Supabase redirect URLs is the same in code and in Supabase
- Added scope in Google cloud console
- Verified that Custom URL scheme is set in Xcode properly

In the web application Google login works perfectly fine. The issue is with iOS application.

Following is the method which I call when trying to perform Google SignIn

func signInWithGoogle() async throws {
        presenter = WebAuthSessionPresenter() // Keep a strong reference

        let oauthURL = try await supabase.auth.getOAuthSignInURL(
            provider: .google, scopes: "email profile openid",
            redirectTo: URL(string: "com.domain.appname://auth/callback")!
        )

        print("oauthURL: \(oauthURL.absoluteString)")
        let session = ASWebAuthenticationSession(
            url: oauthURL,
            callbackURLScheme: "com.domain.appname"
        ) { [weak self] url, error in
            defer {
                // Clean up after flow completes
                self?.presenter = nil
                self?.webAuthSession = nil
            }

            if let error {
                print("Auth Error: \(error)")
                return
            }

            guard let url else { return }

            Task {
                do {
                    print("url: \(url.absoluteString)")
                    try await supabase.auth.session(from: url)
                    print("Google sign-in success")
                } catch {
                    print("Failed to start session: \(error)")
                }
            }
        }

        session.presentationContextProvider = presenter
        session.prefersEphemeralWebBrowserSession = true // optional: avoid Safari cookies
        webAuthSession = session // Keep reference alive
        session.start()
    }
func signInWithGoogle() async throws {
        presenter = WebAuthSessionPresenter() // Keep a strong reference

        let oauthURL = try await supabase.auth.getOAuthSignInURL(
            provider: .google, scopes: "email profile openid",
            redirectTo: URL(string: "com.domain.appname://auth/callback")!
        )

        print("oauthURL: \(oauthURL.absoluteString)")
        let session = ASWebAuthenticationSession(
            url: oauthURL,
            callbackURLScheme: "com.domain.appname"
        ) { [weak self] url, error in
            defer {
                // Clean up after flow completes
                self?.presenter = nil
                self?.webAuthSession = nil
            }

            if let error {
                print("Auth Error: \(error)")
                return
            }

            guard let url else { return }

            Task {
                do {
                    print("url: \(url.absoluteString)")
                    try await supabase.auth.session(from: url)
                    print("Google sign-in success")
                } catch {
                    print("Failed to start session: \(error)")
                }
            }
        }

        session.presentationContextProvider = presenter
        session.prefersEphemeralWebBrowserSession = true // optional: avoid Safari cookies
        webAuthSession = session // Keep reference alive
        session.start()
    }
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

PKCE Auth flow - java.lang.IllegalArgumentException
SupabaseSSupabase / help-and-questions
6mo ago
Auth session missing
SupabaseSSupabase / help-and-questions
11mo ago
Auth Session Missing!
SupabaseSSupabase / help-and-questions
13mo ago
Using Session from PKCE Auth from iOS App to Query Over Tables with Supabase Server Client
SupabaseSSupabase / help-and-questions
3y ago