Categories > Firebase > rex_firebase_userid2id

Introduction

Each UserID could register an alias ID.

UserID might be provided after authentication.

Links


Categories > Firebase > rex_firebase_userid2idIntroductionLinksDependenceUsageData structure on firebaseRandom number IDGet IDGet UserIDRemove UserIDSpecific IDSet IDGet UserIDRemove UserIDRules of data indexing

Dependence

Usage

Data structure on firebase

<sub-domain>\
    <ID> - UserID

One-to-one mapping between UserId and alias ID.


Random number ID

Get ID

UserID --> ID

CallbackYesNoActionis successCondition:On request IDExpression:UserIDExpression:IDCondition:On request ID errorExpression:LastErrorMessageExpression:LastErrorCode Expression:UserIDAction:Get random ID

Sample capx

  1. Action:Get random ID

    • Get ID if UserID has registered,
    • Else, register UserID with a random ID and return this ID
  2. Callback

    • Success : Condition:On request ID

      • Expression:UserID, Expression:ID
    • Failed : Condition:On request ID error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode
      • Expression:UserID

Get UserID

ID --> UserID

CallbackYesNoActionis successCondition:On request User IDExpression:UserIDExpression:IDCondition:On request User ID errorExpression:LastErrorMessageExpression:LastErrorCode Expression:IDAction:Get user ID
  1. Action:Get user ID

  2. Callback

    • Success : Condition:On request User ID

      • Expression:UserID, Expression:ID
    • Failed : Condition:On request User ID error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode
      • Expression:ID

Remove UserID

CallbackYesNoActionis successCondition:On remove User IDExpression:UserIDCondition:On remove User ID errorExpression:LastErrorMessageExpression:LastErrorCode Expression:UserIDAction:Remove User ID
  1. Action:Remove User ID

  2. Callback

    • Success : Condition:On remove User ID

      • Expression:UserID
    • Failed : Condition:On remove User ID error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode
      • Expression:UserID

Specific ID

Set ID

CallbackYesNoActionis successCondition:On request IDExpression:UserIDExpression:IDCondition:On request ID errorExpression:LastErrorMessageExpression:LastErrorCode Expression:UserIDAction:Try set ID

Sample capx

  1. Action:Try set ID

  2. Callback

    • Success : Condition:On request ID, if UserID has not been registered

      • Expression:UserID, Expression:ID
    • Failed : Condition:On request ID error

      • Error : Expression:LastErrorMessage, Expression:LastErrorCode
      • Expression:UserID

Get UserID

See section of Get UserID in Random number ID.

Remove UserID

See section of Remove UserID in Random number ID.


Rules of data indexing

Add data indexing rule to improve the query performance. (Reference)

Assume that sub domain is UserID-ID :

 
xxxxxxxxxx
{  
    "rules": {
        ".read": true,
        ".write": true,
               
        "UserID-ID": {
            ".indexOn": ".value"
        }        
    }  
}