You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter + Supabase iOS端OAuth深度链接失效问题求助

Flutter Supabase OAuth iOS重定向问题解决方案

问题回顾

Web端OAuth登录后可正常重定向回网站,但iOS端登录完成后仍跳转至网站,无法回到APP,已配置CFBundleURLSchemes和关联域名但问题未解决。

具体修复步骤

1. 修正redirectTo参数

将代码中的<Bundle url>替换为实际的APP Bundle ID,例如你的Bundle ID是com.example.myapp,代码应修改为:

Supabase.auth.signInWithOAuth(
  pkg.Provider.apple,
  redirectTo: kIsWeb ? null : 'com.example.myapp://login-callback/',
);

同时在Supabase控制台的Authentication > Settings > OAuth中,将这个iOS重定向URL添加到「允许的重定向URL」列表内。

2. 调整Info.plist配置

  • 替换CFBundleURLSchemes中的通配符和多余域名,只保留你的Bundle ID:
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.example.myapp</string> <!-- 替换为实际Bundle ID -->
        </array>
      </dict>
    </array>
    
  • 添加必要的权限配置,确保iOS允许处理Auth链接:
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
    </dict>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>https</string>
      <string>com.apple.account.appleauth</string>
      <string>com.apple.account.appleauth.redirect</string>
    </array>
    
  • 确认关联域名配置正确,格式为applinks:你的Supabase域名.supabase.co,可在Xcode的「Signing & Capabilities」中添加,或直接在Info.plist中配置对应键值。

3. 实现iOS端URL回调处理

在AppDelegate.swift中添加Supabase深度链接处理逻辑,确保APP能捕获重定向URL:

import UIKit
import Flutter
import supabase_flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ app: UIApplication,
    open url: URL,
    options: [UIApplication.OpenURLOptionsKey : Any] = [:]
  ) -> Bool {
    return SupabaseAuth.instance.handleAuthDeepLink(url)
  }
}

若使用SwiftUI,需在SceneDelegate的openURLContexts方法中执行相同的回调处理。

4. 验证Supabase与Apple开发者配置

  • 检查Supabase控制台中Apple OAuth的配置,确保Service ID、重定向URL与Apple Developer后台一致。
  • Apple Developer后台中,Service ID的「重定向URL」需设置为你的Supabase域名回调地址(如https://your-project.supabase.co/auth/v1/callback),同时确保App ID已关联该Service ID。

5. 清理缓存后重新测试

  • 删除模拟器/真机上的APP,清理Xcode构建缓存(Cmd+Shift+K)。
  • 使用开发者账号或已添加的TestFlight测试账号进行登录测试,避免普通账号的权限限制。

内容的提问来源于stack exchange,提问作者Globe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 14:10:21