Reputation: 299
Hey guys i am having a small issue with Parse for Javascript at the moment, I have used Parse before but for Android and for some reason found it more easier to understand than using it with Javascript.
My current issue is that I am trying to query the User object in my parse database to see whether or not they are an admin or not by checking to see in the "role" column has an integer of 1 or 2. 1 representing a Admin and 2 representing an ordinary user.
If I can remember correctly querying a User is different from querying a normal object in the database, So I am unsure why this query does not carry out correctly. If i take out the query the function works fine and displays the set message of "welcome" in an alert box but when I add in the query it doesnt seem to carry out the function.
My table in the database looks like this:
My current code is as follows:
$('.form-signin').on('submit', function(e) {
// Prevent Default Submit Event
e.preventDefault();
// Get data from the form and put them into variables
var data = $(this).serializeArray(),
username = data[0].value,
password = data[1].value;
// Call Parse Login function with those variables
Parse.User.logIn(username, password, {
// If the username and password matches
var query = new Parse.Query(Parse.User);
query.equalTo("role", 1); //finding the role number
query.find({
success: function(user) {
alert('Welcome!');
},
// If there is an error
error: function(user, error) {
console.log(error);
}
});
});
});
Upvotes: 2
Views: 698
Reputation: 62676
logIn()
is fulfilled with the user that was logged in, so there's no need for an additional query to see that user's attributes. Parse.User.current
is another way to get the current user at any time after a successful login.
Edit - This code logs in a user and checks that the user has role set to the number 1:
Parse.User.logIn(username, password).then(function(user) {
var role = user.get("role");
if (role == 1) {
console.log("login success, role is 1");
} else {
console.log("login success, role is " + role);
}
}, function(error) {
// handle error
});
Upvotes: 2