Как подключиться к одному и тому же документу в firestore с разных устройств? - PullRequest
0 голосов
/ 04 июля 2019

У меня есть функция:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const Firestore = require('@google-cloud/firestore');
const db = admin.firestore();

exports.createCollectionByPlayerID = 
functions.https.onCall((data,context) => {
    const citiesRef = db.collection(context.auth.uid);
    let setSf = citiesRef.doc('1SF').set({
        name: 'San Francisco',
        state: 'CA',
        country: 'USA',
        capital: false,
        population: 260
    });
    return "testID"
});

Я хочу, чтобы эта функция создавала отдельные коллекции (или документы) для каждого игрока, названные по имени игрока.Когда я вызываю эту функцию с одного устройства, функция создает новую коллекцию с одним именем:

pic 1

Когда я вызываю ту же функцию с другого устройства, функция создает другую коллекцию с другимname.

pic 2

Мне нужно подключиться к одной коллекции, созданной одним плеером, с разных устройств без создания новой коллекции.

Мой код Java:

private void hw_fromFunction() {
    FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
    mUser.getIdToken(true)
        .addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
            public void onComplete(@NonNull Task<GetTokenResult> task) {
 if (task.isSuccessful()) {
       String idToken = task.getResult().getToken();

    helloWorldFromFunc(idToken).addOnCompleteListener(new 
    OnCompleteListener<String>() {
        @Override public void onComplete(@NonNull Task<String> task) {}
     });
  } else {}
       }
              });
}

private Task<String> helloWorldFromFunc(String idToken) {
    Map<String, Object> data = new HashMap<>();
    data.put("push", true);
    return mFunctions
            .getHttpsCallable("createCollectionByPlayerID")
            .call(idToken)
            .continueWith(new Continuation<HttpsCallableResult, String>() 
{
                @Override
                public String then(@NonNull Task<HttpsCallableResult> 
task) throws Exception {
                    return (String) task.getResult().getData();
                }
            });
}

Как игрок может подключиться к одной коллекции, названной его идентификатором из разных устройств?

=== Добавлен код Java:

//>>>>>>>>>>>>>>>>*****auth***********
GoogleSignInOptions gso = new 
    GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
         .requestIdToken(getString(R.string.default_web_client_id))
//.requestEmail()
         .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    mAuth = FirebaseAuth.getInstance();

private void signIn() {Intent signInIntent 
    = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);

    startActivityForResult(signInIntent, RC_SIGN_IN);
}

private void signOut() {
    mGoogleSignInClient.signOut().addOnCompleteListener(this
            , new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    updateUI(false);
                }
            });
}

private void revokeAccess() {
    mAuth.signOut();
    mGoogleSignInClient.revokeAccess().addOnCompleteListener(this
            , new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    updateUI(false);
                }
            });
}

Правила в Firestore:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow create: if request.auth != null && request.auth.uid == uid;
    }
  }

}

И Log: (простите за столько текста)

2019-07-05 10:04:21.134 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Connecting to remote service
2019-07-05 10:04:21.169 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Connection attempt already in progress
2019-07-05 10:04:21.281 8802-8802/com.admiral_odessa.firebaseadmiral1 W/zygote: Skipping duplicate class check due to unrecognized classloader
2019-07-05 10:04:21.283 8802-8802/com.admiral_odessa.firebaseadmiral1 I/DynamiteModule: Considering local module com.google.android.gms.signinbutton_dynamite:0 and remote module com.google.android.gms.signinbutton_dynamite:2
2019-07-05 10:04:21.283 8802-8802/com.admiral_odessa.firebaseadmiral1 I/DynamiteModule: Selected remote version of com.google.android.gms.signinbutton_dynamite, version >= 2
2019-07-05 10:04:21.336 8802-8802/com.admiral_odessa.firebaseadmiral1 W/zygote: Skipping duplicate class check due to unrecognized classloader
2019-07-05 10:04:21.338 8802-8846/com.admiral_odessa.firebaseadmiral1 D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2019-07-05 10:04:21.343 8802-8846/com.admiral_odessa.firebaseadmiral1 I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
2019-07-05 10:04:21.420 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Do partial code cache collection, code=30KB, data=28KB
2019-07-05 10:04:21.478 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: After code cache collection, code=28KB, data=28KB
2019-07-05 10:04:21.478 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Increasing code cache capacity to 128KB
2019-07-05 10:04:21.482 8802-8813/com.admiral_odessa.firebaseadmiral1 I/zygote: Background concurrent copying GC freed 11835(1178KB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 1681KB/3MB, paused 781us total 110.398ms
2019-07-05 10:04:21.532 8802-8802/com.admiral_odessa.firebaseadmiral1 D/AutoManageHelper: starting AutoManage for client 0 false null
2019-07-05 10:04:21.545 8802-8802/com.admiral_odessa.firebaseadmiral1 D/AutoManageHelper: onStart true {0=com.google.android.gms.common.api.internal.zaj$zaa@d0b2a33}
2019-07-05 10:04:21.632 8802-8844/com.admiral_odessa.firebaseadmiral1 I/FA: Tag Manager is not found and thus will not be used
2019-07-05 10:04:21.643 8802-8849/com.admiral_odessa.firebaseadmiral1 D/OpenGLRenderer: HWUI GL Pipeline
2019-07-05 10:04:21.692 8802-8851/com.admiral_odessa.firebaseadmiral1 W/DynamiteModule: Local module descriptor class for providerinstaller not found.
2019-07-05 10:04:21.708 8802-8844/com.admiral_odessa.firebaseadmiral1 D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=3100986043983932118}]
2019-07-05 10:04:21.716 8802-8851/com.admiral_odessa.firebaseadmiral1 I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
2019-07-05 10:04:21.716 8802-8851/com.admiral_odessa.firebaseadmiral1 W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
2019-07-05 10:04:21.755 8802-8849/com.admiral_odessa.firebaseadmiral1 I/OpenGLRenderer: Initialized EGL, version 1.4
2019-07-05 10:04:21.755 8802-8849/com.admiral_odessa.firebaseadmiral1 D/OpenGLRenderer: Swap behavior 1
2019-07-05 10:04:21.756 8802-8849/com.admiral_odessa.firebaseadmiral1 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-07-05 10:04:21.756 8802-8849/com.admiral_odessa.firebaseadmiral1 D/OpenGLRenderer: Swap behavior 0
2019-07-05 10:04:21.777 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglCreateContext: 0xa0e9a580: maj 2 min 0 rcv 2
2019-07-05 10:04:21.832 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:21.861 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Do partial code cache collection, code=33KB, data=53KB
2019-07-05 10:04:21.886 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: After code cache collection, code=33KB, data=53KB
2019-07-05 10:04:21.886 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Increasing code cache capacity to 256KB
2019-07-05 10:04:21.891 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2019-07-05 10:04:21.891 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2019-07-05 10:04:21.915 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Connection attempt already in progress
2019-07-05 10:04:21.916 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Connection attempt already in progress
2019-07-05 10:04:21.928 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Activity resumed, time: 32836187
2019-07-05 10:04:22.022 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:22.052 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Do full code cache collection, code=125KB, data=66KB
2019-07-05 10:04:22.052 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: After code cache collection, code=118KB, data=47KB
2019-07-05 10:04:22.061 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Do partial code cache collection, code=118KB, data=48KB
2019-07-05 10:04:22.061 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: After code cache collection, code=118KB, data=48KB
2019-07-05 10:04:22.061 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Increasing code cache capacity to 512KB
2019-07-05 10:04:22.132 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:22.195 8802-8844/com.admiral_odessa.firebaseadmiral1 D/FA: Connected to remote service
2019-07-05 10:04:22.206 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Processing queued up service tasks: 4
2019-07-05 10:04:22.208 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:22.259 8802-8802/com.admiral_odessa.firebaseadmiral1 W/View: dispatchProvideAutofillStructure(): not laid out, ignoring
2019-07-05 10:04:22.259 8802-8802/com.admiral_odessa.firebaseadmiral1 W/View: dispatchProvideAutofillStructure(): not laid out, ignoring
2019-07-05 10:04:22.265 8802-8802/com.admiral_odessa.firebaseadmiral1 W/View: dispatchProvideAutofillStructure(): not laid out, ignoring
2019-07-05 10:04:22.276 8802-8802/com.admiral_odessa.firebaseadmiral1 I/AssistStructure: Flattened final assist data: 6212 bytes, containing 1 windows, 25 views
2019-07-05 10:04:23.633 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:23.698 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:25.666 8802-8849/com.admiral_odessa.firebaseadmiral1 D/EGL_emulation: eglMakeCurrent: 0xa0e9a580: ver 2 0 (tinfo 0xaccfb330)
2019-07-05 10:04:27.514 8802-8844/com.admiral_odessa.firebaseadmiral1 V/FA: Inactivity, disconnecting from the service
2019-07-05 10:05:29.632 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: Do full code cache collection, code=249KB, data=151KB
2019-07-05 10:05:29.633 8802-8807/com.admiral_odessa.firebaseadmiral1 I/zygote: After code cache collection, code=158KB, data=105KB
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...