Skip to content

Is it possible to use Custom Token while observing a Collection? #2419

@jimisdrpc

Description

@jimisdrpc

In few words, is it possible to add an idToken when observing/listening a Collection throw snapshotChanges or valueChanges or any other method?

With this code in Angular I can observe changes in an entire collection (transfer is my Firestore collection):

public transfers: Observable<any[]>; constructor(db: AngularFirestore) { this.transfers = db.collection('/transfer').valueChanges();

and with this code I can observe a specific document:

public transfers: Observable<any[]>;
transferCollectionRef: AngularFirestoreCollection;

constructor(db: AngularFirestore) {

this.transferCollectionRef = db.collection<any>('transfer', ref => ref.where("id", "==", "1"));
this.transfers = this.transferCollectionRef.snapshotChanges().map(actions => {
  return actions.map(action => {
    const data = action.payload.doc.data();// as Todo;
    const id = action.payload.doc.id;
    return { id, ...data };
  });
});

With this curl command I can use token also but obviously I curl isn't going to keep observing. I am just pasting curl scrupt to clarify what I mean by idToken generated from a Custom Token

curl --location --request POST 'https://firestore.googleapis.com/v1/projects/firetestjimis/databases/(default)/documents:runQuery'
--header 'Authorization: Bearer eyJh..... a valid idToken returned from
https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key ..... kUifgEtHT4ZXde1ehf_PIwNDx6_ZfJuQ'
--header 'Content-Type: application/json'
--data-raw '{
"structuredQuery": {
"where" : {
"fieldFilter" : {
"field": {"fieldPath": "id"},
"op":"EQUAL",
"value": {"stringValue": "1"}
}
},
"from": [{"collectionId": "transfer"}]
}
}'

So, my question is: how can I use same idToken while listening a Collection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions