Skip to content

Returning a role for null user #3923

Closed
Closed
@dpatel20

Description

@dpatel20

I am using parse server on back4app. I am checking for admin role using the code shown here - shown below for ease:

function userHasRole(user, roleName) {
    var query = new Parse.Query(Parse.Role);
    query.equalTo("name", roleName);
    query.equalTo("users", user);
    return query.find().then(function(roles) {
        return roles.length > 0;
    });
}
var currentUser = Parse.User.current();
// is the user an "admin"?
userHasRole(currentUser, "admin").then(function(isAdmin) {
    console.log((isAdmin)? "user is admin" : "user is not admin");
});

I have a role admin which is connected to exactly one user named admin (as confirmed in the Parse Dashboard). With no user logged in (debugging shows current user = null), I get a role returned (admin role!). Again, I have checked the role in debug to show it is a valid role object. I have tried this on other browsers where I am sure I have never been logged in and get the same result.

Edit: I have tried with a different role and get the same result. Something like: if user is null, then the query always returns the role mentioned by roleName. I guess parse server ignores null in queries??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions