【发布时间】:2020-07-14 11:27:30
【问题描述】:
我正在使用 Firebase Admin SDK 来完成管理功能。我已部署的功能位于控制台中的 Firebase Cloud Function 上。我已经能够从应用程序中调用这些函数,但是我不知道从我通过调用发送的映射数据中获取值。如果我是正确的,那应该可以通过request 变量进行检索,但是当我尝试诸如request.email 之类的东西时,这似乎不是一个有效的论点。
MainActivity.java
public Task<String> callCloudFunction() {
FirebaseFunctions mFunctions = FirebaseFunctions.getInstance();
Map<String, Object> data = new HashMap<>();
data.put("email", "new@example.com");
data.put("password", "changePassword");
data.put("displayName", "Mike Example");
data.put("trainerId", "Mike Example");
data.put("photoURL", "NULL");
return mFunctions
.getHttpsCallable("mkUser")
.call(data)
.continueWith(new Continuation<HttpsCallableResult, String>() {
@Override
public String then(@NonNull Task<HttpsCallableResult> task) {
// This continuation runs on either success or failure, but if the task
// has failed then getResult() will throw an Exception which will be
// propagated down.
return (String) task.getResult().getData();
}
});
}
index.ts
export const mkUser = functions.https.onRequest((request, response) =>{
admin.auth().createUser({
email: request.email, //IS NOT A VALID ARGUMENT ('email' CANNOT BE FOUND)
emailVerified: false,
password: 'secretPassword',
displayName: 'John Doe', //VALUES ARE HARDCODED BUT I WOULD LIKE TO USE 'Mike Example' SENT FROM MAIN ACTIVITY
photoURL: 'http://www.example.com/12345678/photo.png',
disabled: false
})
.then(function(userRecord: { uid: any; }) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.uid);
})
.catch(function(error: any) {
console.log('Error creating new user:', error);
});
});
【问题讨论】:
标签: node.js typescript httprequest android-json