How to check if user is admin?
-
Is there a quicker way to tell, on the server-side, in a plugin, if the current user is an admin?
Right now, I'm doing this:
groups.isMember(req.user, "administrators", function(err, bool){ if(bool){ // do stuff } });
Is there a shortcut to that?
Thanks.
-
groups.isMember
takes in user id as the first param so your code should bevar uid = req.user ? req.user.uid : 0; groups.isMember(uid, "administrators", function(err, bool) { });
Alternatively you can use
var uid = req.user ? req.user.uid : 0; user.isAdministrator(uid, function(err, isAdmin) { });
-
Alright, thanks guys.
The
user.isAdministrator
function was what I was looking for.
Copyright © 2024 NodeBB | Contributors