Hi, hopefully I am posting in the correct forum thread, if not, let me know please. I am currently working on an app that, after being authenticated to Google’s Firebase (which is working), I want to then POST data to that same Firebase’s database via its API. See code below.
Here is where the function first gets called (added -----> to call attention to the function in question)
var createUser = function() {
var email = userEmailInput.value;
var password = userPasswordInput.value;
EAuth.createWithEmailAndPassword(email, password).then(function(user) {
signedIn();
-----> putUser(); <-------
router.goto("home");
}).catch(function(e) {
console.log("Signup failed: " + e);
FirebaseUser.onError(e, -1);
});
};
that function when called then runs this bit of code
function putUser() {
var url = encodeURI(ROOT_URL);
fetch(url, {
method: 'POST',
headers: { "Content-Type": "application/json"},
body: JSON.stringify(userInfo)
}).then(function(response) {
console.log("inreponse");
return response.json();
-----> }).then(function(responseObject) { <------
console.log(JSON.stringify(responseObject));
if (responseObject.object == 'token') {
console.log("wemadeittohere");
}
if (responseObject.error) {
console.log(" 1 Error: " + responseObject.error.message);
}
}).catch(function(err) {
console.log("2 Error: " + err);
});
console.log("afterputUser");
}
I have a lot of console.log’s to help me track the process and see what works and what doesn’t. Everything works up until the responseObject line (again marked with -----> for emphasis). It skips it and runs the catch(function(err) instead, and I don’t know why. What am I supposed to do with that responseObject?
-All I get in the command prompt is an error that says “2 Error: SyntaxError: Unexpected token a in JSON at position 0”.
Thank you for your help in advance! If anything is unclear, let me know!