首页 > 解决方案 > 如何修复 Flutter 中的“由于缺少初始状态而无法处理请求。”,来源:https://{org-name}/__/auth/handler.js

问题描述

我正在尝试在我的颤振应用程序中设置社交登录。谷歌和 Facebook 登录工作正常,但是当我尝试使用 github 登录时,它会打开一个网页询问我的 github 凭据,当我点击登录时,我得到了这个。
由于缺少初始状态,无法处理请求。”,来源:https://{org-name}/__/auth/handler.js
我有一个以 MongoDB 作为数据库的自定义后端。我尝试注册的代码/登录是:

Navigator.of(context).pushReplacement(MaterialPageRoute(
    builder: (context) => Scaffold(
      body: SafeArea(
          child: Builder(
        builder: (context) => WebView(
          userAgent: "random",
          initialUrl:
              'https://{orgname}.herokuapp.com/api/auth/$url',
          javascriptMode: JavascriptMode.unrestricted,
          navigationDelegate: (navigation) async {
            if (navigation.url.startsWith(
                'https://{org-name}.herokuapp.com/api/auth/$url/callback')) {
              print('success');
              
              http.Response response =
                  await http.get(Uri.parse(navigation.url));
              print('response is ${response.body}');
              final storage = FlutterSecureStorage();
              var parsedBody = json.decode(response.body);
              await storage.write(key: "token", value: parsedBody["token"]);
              Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(
                    builder: (context) => Home(),
                  ));
            }
            return NavigationDecision.navigate;
          },
        ),
      )),
    ),
  ));
}

在 Androidmanifest.xml 我只有这个:

<intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

和这个

<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/fb_login_protocol_scheme" />
</intent-filter>

请帮忙。

标签: flutterandroid-manifest

解决方案


推荐阅读