简体   繁体   English

Firebase 可调用 Function 返回空数据

[英]Firebase Callable Function returning nill data

I'm doing firebase auth on the backend and it's working.我在后端执行 firebase 身份验证,它正在运行。 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.它正确地创建了用户,并且我在控制台日志中得到了 UUID,但是当我尝试发回用户的 UUID 时,我得到了一个空响应。 I've already tried all the solutions on other stackoverflow responses and none have worked for me.我已经尝试了其他 stackoverflow 响应的所有解决方案,但没有一个对我有用。

This is my firebase callable function.这是我的 firebase 可调用 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这是我的 swift 代码

  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)")
            }
        }

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
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM