How to create an Index of Tokens?

I am using Firebase Auth with FaunaDB, whenever a user logs in I hit my endpoint which generates a token for the user who is referenced by Firebase and returns it, which is then used in the client for the rest of the queries. Rather than creating a new token everytime the same endpoint is called, I want to check if the user has any existing token. How do I create an Index to find the same ?

The Tokens() collection can be indexed like anything else.

CreateIndex({
  name: 'tokens_by_instance',
  source: Tokens(),
  terms: [
    { field: ['instance'] }  
  ]
})

And a token can have data like any other Document. If you add data to the tokens you can index based on that too.

CreateIndex({
  name: 'tokens_by_metadata',
  source: Tokens(),
  terms: [
    { field: ['data', 'meta'] }  
  ]
})
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.