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()
}
1 Reply
Subin
SubinOP7d ago
@supabase Appreciate any help here. Thanks

Did you find this page helpful?