I have created a Cloud Function using TypeScript, with async
calls included.
exports.verifyOtp = functions.https.onCall((data,context)=>{
phoneNumber = data.phoneNumber;
otp = data.otp;
let email:string = data.email;
let password:string = data.password;
let displayName:string= data.displayName;
authFunction.validateOtp(phoneNumber, otp,(otpErr,otpValue) => {
if(otpErr){
console.error(otpErr);
return {otpErr};
}else{
return authFunction.createUser(email,false,phoneNumber,password,displayName,false,(err,value) => {
if(err)
{
console.error(err);
return Promise.reject(err);
}
else{
console.log(value);
return Promise.resolve(value);
}
});
}
});
});
Provided below is the code for authFunction.validateOtp
validateOtp(phoneNumber:string, otp:string,callback:Function){
let otpValidationApi:string = "https://<api>/verifyRequestOTP.php?authkey="+this.authKey+"&mobile="+phoneNumber+
"&otp="+otp;
https.get(otpValidationApi, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
let result = JSON.parse(data);
var y=result.type;
callback(null,y);
});
}).on("error",(err)=>{
console.log("Error: "+err.message);
});
}
I am attempting to receive the output/return value on my Android app using:
private static FirebaseFunctions mFunctions = FirebaseFunctions.getInstance();
mFunctions.getHttpsCallable(nameOfFunction).call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
String result2 = (String) task.getResult().getData();
return result2;
}
});
Nevertheless, the variable result2
in the Android code consistently returns null, despite the Cloud Function working correctly as anticipated.
Could you please assist me in identifying my mistake?