Block about page


(Kgish) #1

I would like to block the about page, e.g. for users that are not logged in. How can I do this?


(TechnoBear) #2

I’m pretty sure you’re looking for this, under Settings > Users (right at the bottom of the page):


(Kgish) #3

That’s already checked in my settings, so it must be something different.


(Joshua Rosenfeld) #4

Just checking, you want to block http://my_site_name/admin like Discourse Meta, not anything to do with user profiles, right?


(TechnoBear) #5

Ah - my mistake. I was thinking of the “About Me” setting.


(Kgish) #6

I want to block /about (e,g. redirect to 404-page) if visitor is not logged in.


(Kane York) #7

Hmm, pretty sure there’s no way to do that right now except making the entire site login-required.


(Kgish) #8

For those interested, here’s how I solved this:

api.onPageChange((url, title) => {
    if (!api.getCurrentUser() && /\/about/.test(url)) {
        if (about_hide && about_hide.length > 0) {
            about_hide.split(/[ ,:;]/).forEach(function(section){
                $(`section.about.${section}`).hide();
            })
        }
    }
}

Where about_hide is a list of section classes that need to be hidden.


(Sam Saffron) #9

note, the data is all still there, if that is the approach you are going for… why not use CSS?


(Kgish) #10

Sure I could use CSS, but in this case I need to hide things only when a user is not logged in: !api.getCurrentUser().

Am not familiar of any way to achieve this using just CSS.


(cpradio) #11

It would be

.anon section.about {
  display:none;
}

(Kgish) #12

Cool, didn’t know that!