I see this tc throws errors when one is not logged in because of a wrong order of expressions
if (settings.admin_only && currentUser.admin && currentUser !== null) {
evaluates currentUser.admin even if currentUser is null. It should be
if (settings.admin_only && currentUser && currentUser.admin) {