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

Flutter集成本地Supabase时Google OAuth登录重定向失败问题

本地Supabase + Flutter OAuth登录重定向失败问题

我基于Supabase搭建Flutter项目,用Supabase托管服务时登录功能正常,但部署本地Supabase后遇到配置问题:在可访问localhost的iPhone模拟器上完成Google登录后,浏览器尝试重定向到localhost:3000/#access_token=<THE-TOKEN>&expires_in=3600&provider_token=<THE-TOKEN>&refresh_token=<TOKEN>&token_type=bearer,返回"no Route matched with those values",无法跳回APP。

本地Supabase的config.toml配置片段

[auth]
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
# in emails.
site_url = "http://localhost:54321" 
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
additional_redirect_urls = ["https://localhost:3000", "http://localhost:54321/auth/v1/callback"]

...

[auth.external.google]
enabled = true
client_id = "xxx.apps.googleusercontent.com"
secret = "xxx"
redirect_uri = "http://localhost:54321/auth/v1/callback"

Flutter端登录代码

await Supabase.instance.client.auth.signInWithOAuth(
  Provider.google,
  redirectTo: 'my.registered.app://login-callback/',
);

问题原因与解决方案

核心问题是重定向URL的配置不匹配,需要同步以下几个地方:

1. 修正本地Supabase的config.toml

  • 更新additional_redirect_urls,把APP的自定义scheme加入允许列表:
    additional_redirect_urls = [
      "https://localhost:3000", 
      "http://localhost:54321/auth/v1/callback",
      "my.registered.app://login-callback/"
    ]
    
  • 确保site_url设置为本地Supabase的默认地址http://localhost:54321(不要和Flutter的端口混淆)

2. 更新Google Cloud控制台的重定向URI

在Google Cloud的OAuth 2.0客户端ID设置中,添加APP的自定义scheme:my.registered.app://login-callback/(和Flutter代码、Supabase配置完全一致)

3. 确保Flutter端参数一致

确认signInWithOAuth中的redirectTo值和上述配置完全匹配,包括大小写、斜杠等细节

4. 重启本地Supabase服务

修改config.toml后必须重启Supabase,否则配置不会生效

完成以上步骤后,Google登录成功后会正确跳回你的Flutter APP,而不是尝试访问localhost:3000的网页路由。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 20:47:45