Hi Guys,
I’ve been having some real trouble with this issue, As mentioned before I am trying to achieve the following:
- My ‘admin’ inputs the ‘users’ firstname, surname, email (and other details)
- My function, firstly, writes inputted information into the appropriate ‘public’ area of the database, then logs out the current user (admin) (works fine)
- Registers the new user using firebaseAuth (which works and they appear as an authenticated user
(THIS is where i’m having issues), what should happen is:
- Whilst ‘logged in’ as the new user, I use my firebase.setUserValue, to write the above data, also to the user specific private branch
- Log out, and log back in as the admin – all in the background.
For some reason, even though I am logged out, and then authenticated as the new user, it is not working with the firebase.setUserValue(), although my console is returning ‘write completed’
I have tried splitting this function into 2, by calling return; at the end of the initial registration, then storing the data/logging out/in separately to see if this was an issue with async, what could be causing this behaviour? as the function is nearly identical to my standard user registration one which works fine! Function below:
function adminAddUser (AddFirstname, AddSurname, addSubGroup, AddEmail) {
var i = getMySpecialYear(date)
var addRegisterDetails = ({"firstname": AddFirstname, "surname": AddSurname, "email": AddEmail, "group": groupName, "subGroup": addSubGroup})
firebaseDb.setValue("groups" + "/" + groupName + "/" + "users" + "/" + AddFirstname + " " + AddSurname + "/" + "details", addRegisterDetails)
addPass = makeid(24)
firebaseAuth.logoutUser();
stack.popAllExceptFirstAndPush(homePage)
return adminAddUserValues(AddEmail, addPass, AddFirstname, AddSurname, addSubGroup)
}
function adminAddUserValues(AddEmail, addPass, AddFirstname, AddSurname, addSubGroup) {
firebaseAuth.registerUser(AddEmail, addPass)
console.log(AddEmail + addPass+ AddFirstname + AddSurname + addSubGroup + groupName)
var addUserDetails = ({"firstname": AddFirstname, "surname": AddSurname, "email": AddEmail})
firebaseDb.setUserValue("subGroup", addSubGroup)
firebaseDb.setUserValue("details", addUserDetails,
firebaseAuth.logoutUser()
firebaseAuth.loginUser(email, userPass)
}