Hide all webpages behind login

What is the best way to redirect navigation to any webpage to the ‘/login’ for Guest users?

Inside ‘website / website settings’ it is possible to replace the home page with login as the default page, but the home page is still externally accessible by navigating to ‘/home’

Likewise, it is possible to reach a large number of pages including custom webpages just by navigating directly via URL - so, what is the best way to protect the whole website behind Login as it is desired to have the website utilised on a private intranet.

The closest solution I have found involves including this snippet in the get_context functions for any given page:

def get_context(context):
    if frappe.session.user == 'Guest' and frappe.session.data.user_type != 'System User':
    frappe.local.flags.redirect_location = '/login'
    raise frappe.Redirect

However, this would need to be included in the .py file for every single page of the site which is many, and there’s a high chance of pages missed.

Is there a way to blanket privatise the website and all pages for only users that are logged in?


There’s a hook get_website_context. I think it will be invoked for any page.

This sounds very promising! Where is the code for the hook, I did a search of the whole codebase and can’t seem to find it

Got the name wrong, its like this: