I made a database for accounts login for a web app with back4app, it works on Firefox-ish but doesn't work on Chrome at all. on FF, I try to log in and it gives me a parse error 200 username/password required, I reload the page and it works (I don't know why it does that btw and I want to fix that too). The same trick however doesn't work on Chrome, whenever I reload it just clears the fields and doesn't let me in. I looked up the error, and it turns out that the post request doesn't take the info from the input fields for some reason. Here's the login window's HTML:
<dialog id="login">
<h1>تسجيل دخول</h1>
<input type="text" id="loginid" placeholder="id" pattern="[A-Za-z]">
<input type="password" id="loginpass" placeholder="password">
<button type="submit" id="loginButton">دخول</button>
</dialog>
and that's the JS behind it, it's vanilla by the way
const login = document.querySelector('#login');
let loginid = document.querySelector('#loginid').value;
let loginpass=document.querySelector('#loginpass');
const loginButton = document.querySelector('#loginButton');
login.style.display='block';
loginButton.onclick = function() {
let user=Parse.User.logIn(loginid,loginpass.value).then(function(user){
alert(`Welcome ${user.get('username')}`);
login.style.display='none';
membersDiv.style.display='block';
addMemberArea.style.display='block';
}).catch(function(error){
alert(error);
})
}
CodePudding user response:
It looks like you're using the Parse JavaScript SDK to log in users. Based on the code you've shared, it looks like you're not passing the correct parameters to the Parse.User.logIn() method.
The logIn() method takes two parameters - the first is the username, and the second is the password. Based on your code, it looks like you're passing the value of the input field (which is currently empty) as the username, and the password as the second parameter.
You'll want to change your code so that it passes the username and password input fields as the two parameters, like so:
Parse.User.logIn(usernameInput.value, passwordInput.value).then(function(user){
alert(`Welcome ${user.get('username')}`);
login.style.display='none';
membersDiv.style.display='block';
addMemberArea.style.display='block';
}).catch(function(error){
alert(error);
})
For more information on logging in users with the Parse JavaScript SDK, check out the documentation here: