Supabase Auth问题:Google登录后跳转至Google而非应用的解决方法
Google登录后无法返回Flutter应用的解决方案
完成Google登录后跳转到Google.com而非返回应用,核心是重定向规则不匹配或应用配置缺失,结合你的代码和配置,按以下步骤排查修复:
1. 对齐重定向URI与App Auth配置
你的代码中生成的redirectUrl是反转后的Google Client ID前缀 + :/,但build.gradle里的appAuthRedirectScheme设置的是applicationId(com.user.appname),两者必须完全一致。
修复方式二选一:
- 改代码:把
redirectUrl改成'com.user.appname:/'(和你的applicationId一致) - 改
build.gradle:将appAuthRedirectScheme替换为反转后的Client ID前缀,比如Client ID是12345-abc.apps.googleusercontent.com,反转后就是com.googleusercontent.apps.abc-12345,配置如下:defaultConfig { // ... 其他配置 manifestPlaceholders += [ 'appAuthRedirectScheme': 'com.googleusercontent.apps.abc-12345' ] }
2. 配置Google Cloud控制台的重定向URI
必须在Google Cloud的OAuth凭据中添加正确的重定向地址:
- 进入Google Cloud控制台 → 你的项目 → API和服务 → 凭据 → 找到对应的Android客户端ID
- 在「授权重定向URI」中添加:
[反转后的Client ID前缀]:/(比如com.googleusercontent.apps.abc-12345:/) - 保存后等待5-10分钟让配置生效
3. 检查AndroidManifest.xml的Intent Filter
确保MainActivity中添加了接收重定向的规则,flutter_app_auth依赖这个规则捕获跳转:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="@string/app_auth_redirect_scheme" /> </intent-filter>
注:@string/app_auth_redirect_scheme会自动读取build.gradle的配置,无需手动修改。
4. 验证Nonce传递正确性
确认代码中nonce的传递逻辑:
AuthorizationRequest里的nonce是哈希后的nonce(你的代码里是hashedNonce,正确)supabase.auth.signInWithIdToken里的nonce是原始nonce(你的代码里是rawNonce,正确)
如果之前修改过这段逻辑,重新核对一遍。
5. 清理缓存重新构建
- 执行
flutter clean清理Flutter缓存 - 卸载设备上的旧应用,重新运行
flutter run
内容的提问来源于stack exchange,提问作者faccio
相关产品推荐
相关产品推荐

