'Firebase Callable Function returning nill data

I'm doing firebase auth on the backend and it's working. It's correctly creating the user and I get the UUID in the console log, however when I try to send back the user's UUID I get a nill response. I've already tried all the solutions on other stackoverflow responses and none have worked for me.

This is my firebase callable function.

exports.create_user_auth = functions.https.onCall((data, context)=> {

    const email = data.email;
    const password = data.password;

    return admin.auth().createUser({
        email: email,
        emailVerified: false,
        password: password,
    })
    .then((userRecord) => {
        // response.status(200).send("Successfully created new user: " +userRecord.uid);
        console.log(`UserRecord ${userRecord}`)
        console.log(`UserRecord ${userRecord.uid}`)
        return userRecord.uid
    })
    .catch((error) => {
        // response.status(400).send("Failed to create user: " + error);
        return error
    });
    
});

This is my swift code

  Functions.functions().httpsCallable("create_user_auth").call(data) { (result, error) in
                if result != nil {
                    print("Result: \(result)")
                    print("data", result?.data)
                    let userId = result!.data as? String
                    print("UserId: \(userId)")
//                  onSuccess(offerId!)
                    
                }
            
            if error != nil {
                print("Error: \(error)")
            }
        }


Solution 1:[1]

This is the new working code

exports.create_user_auth = functions.https.onCall(async (data, context)=> {

const email = data.email;
const password = data.password;
var uuid = ""

await admin.auth().createUser({
    email: email,
    emailVerified: false,
    password: password,
})
.then(async (userRecord) => {
    // response.status(200).send("Successfully created new user: " +userRecord.uid);
    console.log(`NEW UPDATE`)
    console.log(`UserRecord ${userRecord}`)
    console.log(`UserRecord ${userRecord.uid}`)
    uuid = userRecord.uid
    // return userRecord.uid
    
})
.catch((error) => {
    // response.status(400).send("Failed to create user: " + error);
    return error
});

console.log(`UUID OUTSIDE: ${uuid}`)
return uuid
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ximena Flores de la Tijera