如何在Firebase中创建新用户后禁用自动登录?
管理员只能添加新用户。我的问题是,当我创建一个新用户时,它会自动登录该用户,然后注销管理员。如何在Firebase中创建新用户后禁用自动登录?,firebase,authentication,firebase-authentication,Firebase,Authentication,Firebase Authentication,管理员只能添加新用户。我的问题是,当我创建一个新用户时,它会自动登录该用户,然后注销管理员。 仅供参考。我没有使用管理员SDK。火基 我的代码: var password = $('#row' + x + 'cell1').val(); var fname = $('#row' + x + 'cell2').val(); var email = teacherID + "@gmail.com";
仅供参考。我没有使用管理员SDK。火基 我的代码:
var password = $('#row' + x + 'cell1').val();
var fname = $('#row' + x + 'cell2').val();
var email = teacherID + "@gmail.com";
console.log(email + password);
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user) {
//Add to users table
var pushedUser = firebase.database().ref('users/' + user.uid).set({ role: "Teacher",
fullname: fname });
//Add name and default dp to the Authorization table
user.updateProfile({
displayName: fname,
photoURL: "default_dp",
});
var $rowFirst = $("table:first").find("tr:first");
var $rowNext = $('#tblCSVaccounts tr').eq(x);
//get all td's in row
var $tdsFirst = $rowFirst.find("td");
// loop all td
$.each($tdsFirst, function(i, el) {
//get value of each td
var txtEntity = $(this).find("input").val();
var $rowNext = $('#tblCSVaccounts tr').eq(x);
var $tdsNext = $rowNext.find("td:eq(" + i + ")");
$.each($tdsNext, function(i, el) {
//get value of each td
var txtValue = $(this).find("input").val();
//Update in database
const mySection = $('#sectionUpload').val();
var pushedRef = firebase.database().ref('Teachers/' + user.uid).update({ [txtEntity]: txtValue });
$('#alert-success').removeClass('hide');
});
});
}, function(error) {
// An error happened.
var errorCode = error.code;
var errorMessage = error.message;
});
您可以使用
firebase.auth().onAuthStateChanged(…)
希望它能帮助你,伙计 请添加用于创建新用户的代码。@Hareesh添加了代码:)请参考此答案如果您正在构建用于创建用户的管理UI,最好使用Firebase管理SDK。它们提供了一个
createUser
API()来实现这一点。您正在使用的客户端API是针对最终用户的。当用户注册时,他们会直接登录。