1

我是 Firebase 的新手,所以任何见解都值得赞赏。我正在编写 Java 服务器端测试代码。我从数据库中获取了几个用户,并试图将数据迁移到 Firebase 中经过用户身份验证的节点。我的代码从数据库中选择了几个用户,并为每个用户启动了一个新线程。

第一个线程连接并成功验证。随后的同时身份验证尝试失败,并显示以下错误消息。每个线程都有自己的 Firebase 引用对象实例。同时登录的数量是否有限制,可能来自同一个 IP 地址?尚未在文档中找到任何内容。

如果我将代码更改为在单个线程中运行并逐个登录和注销每个用户,那么我不会收到错误消息。

任何见解都非常感谢。

Message: -5
Message: Due to another authentication attempt, this authentication attempt was aborted before it could complete.

            Firebase ref = new Firebase("https://<instance>.firebaseio.com/");

            ref.authWithPassword(mEmail, mPassword, new Firebase.AuthResultHandler() {
            @Override
            public void onAuthenticated(AuthData authData) {
                System.out.println("Successfully authenticated: " + mEmail);
                user.setUID(authData.getUid());
                user.setCurrentUserRef(ref);
                done.set(true);
            }

            @Override
            public void onAuthenticationError(FirebaseError firebaseError) {
                System.out.println("Error during authentication: " + mEmail);
                System.out.println("Error during authentication: " + ref.toString());

                System.out.println("Message: " + firebaseError.getCode());
                System.out.println("Message: " + firebaseError.getDetails());
                System.out.println("Message: " + firebaseError.getMessage());

                done.set(true);
            }});
            waitForCompletion(this.getClass().getName());
4

1 回答 1

4

如果您因为安全规则而作为不同的用户进行身份验证,则使用服务器令牌是更好的解决方案。

Firebase 连接在任何给定时间最多只能让一个用户通过身份验证。但是,在 Firebase Java 库中,有一个未记录(且不受官方支持)的解决方法来创建多个独立连接。在包中的类中,com.firebase.client您可以运行以下代码

// important this code needs to be in the package com.firebase.client
Config config1 = new Config();
Config config2 = new Config();
Firebase ref1 = new Firebase("https://<your-firebase>.firebaseio.com", config1);
Firebase ref2 = new Firebase("https://<your-firebase>.firebaseio.com", config2);
// ref1 and ref2 will now have independent connections, listeners and authentication states

请注意,这些也会打开与服务器的独立连接。

于 2015-05-12T20:45:57.127 回答