My database hierarchy. I'm using Firebase Realtime-Database
I'm trying to send string(name) to cloud functions, make cloud function do a search in "AllCharacterNames" node by received string(name) from Unity, and then, return found result string back to Unity (even if string null or empty).
My Unity function:
private void CheckIfNameExists(string name)
{
var function = functions.GetHttpsCallable("checkName");
function.CallAsync().ContinueWithOnMainThread((response) =>
{
if (response.IsFaulted || response.IsCanceled)
{
Debug.LogError("Fault!");
}
else
{
string returnedName = response.Result.Data.ToString();
if(returnedName == name)
{
//Name already exists in database
}
else if (string.IsNullOrEmpty(returnedName))
{
//Name doesn't exist in database
}
}
});
}
My Cloud Function:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.checkName = functions.https.onCall(async (data) => {
if (!data.exists()) {
return null;
}
const name = data.val();
var dbRef = admin.database().ref("AllCharacterNames");
return dbRef.orderByValue().equalTo(name).once("value").then(function (snapshot)
{
return snap.val();
});
});
Can someone kindly explain what i'm doing wrong? Thanks!