[英]I tried making a callable function for createUser but I am getting an error wen I run it and I can't figure out why
I am trying to make a user management page and I set up a callable function to run on my web app on firebase to create a new user.我正在尝试制作一个用户管理页面,并设置了一个可调用的函数,以在 firebase 上的 Web 应用程序上运行以创建一个新用户。 The html function is designed to update users or create new ones.
html 函数旨在更新用户或创建新用户。 I am trying to test saving a new user.
我正在尝试测试保存新用户。 As far as I can tell, all the variables match up, but it still receives an error.
据我所知,所有变量都匹配,但它仍然收到错误。 The error isn't helpful, so I can't tell what's wrong.
该错误没有帮助,所以我不知道出了什么问题。 Can someone help?
有人可以帮忙吗?
userManagement.html用户管理.html
function save(){
if(document.getElementById("password").value === document.getElementById("p2").value){
if(document.getElementById("username").value === ""){
const createUser = firebase.functions().httpsCallable("createUser");
createUser({ email: document.getElementById("email").value, name: document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, password: document.getElementById("password").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
}
else{
const updateUser = firebase.functions().httpsCallable('updateUser');
// Passing params to data object in Cloud functinon
updateUser({ email: document.getElementById("email").value, name: document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, uid: document.getElementById("username").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
if(!(document.getElementById("password").value === "")){
const updatePassword = firebase.functions().httpsCallable('updatePassword');
// Passing params to data object in Cloud functinon
updatePassword({password: document.getElementById("password").value, uid: document.getElementById("username").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
}
}
}
else{
alert("password and confirm do not match")
}
}
index.js索引.js
export const createUser = functions.https.onCall(async (data, context) => {
const {email, name, phone, password} = data;
await admin
.auth()
.createUser({
email: email,
displayName: name,
phoneNumber: phone,
password: password,
emailVerified: true,
disabled: false,
}).then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
}).catch(console.error);
return {data: `User updated`}
});
the imports for the pages are:页面的导入是:
<script src="/__/firebase/8.7.1/firebase-app.js"></script>
<script src="/__/firebase/8.7.1/firebase-analytics.js"></script>
<script src="/__/firebase/8.7.1/firebase-auth.js"></script>
<script src="/__/firebase/8.7.1/firebase-functions.js"></script>
<script src="/__/firebase/8.7.1/firebase-firestore.js"></script>
<script src="/__/firebase/init.js?useEmulator=true"></script>
and和
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
Current errors:当前错误:
Someone helped me.有人帮助了我。 I forgot to initialize admin sdk.
我忘了初始化 admin sdk。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.