         roleName = result.value
       app.models.roles.findOneBy 'name', roleName, user.systemId
       , (err, obj) ->
-        if obj and not err
+        if obj?._id? and not err
           _.each(user.roles, (role) ->
             if role.toString() is obj._id.toString()
               result = true

        else
          res.json 401, {}

  isInRole = (role, user, callback) ->
    result = false
    settingName = role + 'RoleName'

  #Export the authentiaction action middleware
    publicAction: publicAction
    publicReadAction: publicReadAction
    roleAction: roleAction
    userAction: userAction
    adminAction: adminAction
    sysAdminAction: sysAdminAction
