Hey everyone, I’m stuck with a problem in the Monaca backend demo. I’ve been trying to set up user registration and login, but it’s not working. When I test it in the debugger, I get this error:
Uncaught TypeError: Cannot read property 'error' of null
It happens on line 21 of app.js, in the registration function. Here’s what the code looks like:
function signUp() {
let userEmail = $('#signup_email').val();
let userPass = $('#signup_password').val();
console.log(BackendService);
BackendService.User.create(userEmail, userPass)
.then(() => {
console.log('Yay! Signed up successfully: ' + BackendService.User._id);
$.mobile.changePage('#MainView');
})
.catch((error) => {
console.log('Oops, something went wrong');
alert('Sign up failed. Please try again.');
console.error(JSON.stringify(error));
});
}
I think it might be having trouble connecting to the User collection, but I’m not sure why. Has anyone run into this before or know how to fix it? Thanks!
I have experienced a similar issue with Monaca’s backend error handling. Often, this error appears when the create method does not return a valid error object, which may be due to network problems or improper backend configuration. I recommend verifying that your API keys, endpoints, and connection settings are correct. It also helped to adjust the error handling by checking if the error object is null before trying to access its properties. Using debugging techniques to inspect the actual response has been useful in diagnosing and resolving the problem.
hey flyingeagle, that error is a pain! ive seen it before. try wrapping ur error handling in a try-catch block. also, double-check ur BackendService initialization. sometimes the service isnt fully loaded when the function runs. u could add a small delay or use a callback to make sure its ready. good luck!
hey flyingeagle, r u sure you are catching every detail? i noticed the error object might be missing some info. what if u check if BackendService.User is defined before calling create? also, is ur connection stable?