
My website has public pages and non-public pages. Only a logged in user can access the non-public pages. My question is: how do we prevent non logged in people from accessing those pages.
The following nodejs controller method renders the view \admin\index
. What code needs to be added to prevent non logged in users from accessing the view?
exports.getIndex = async(req,res) => {
// How do I block this view from rendering if the user is not logged in?
// I.e. how do I check to see if there is a session record when this view is accessed?

Fetch the current user, if nothing is returned either don't render the page or redirect them to a login page.

Can the current User be fetched by a non logged in user?

if they're not logged in it will return nothing

I think in this case, an error would be generated.

try {
const user = await account.get();
} catch (error) {
redirect("login");
}

You can do something like this.

ok thanks Kenny.
Recommended threads
- Console create row ui not passing ID.uni...
I'm getting an error saying the id is already used but it should be created with ID.unique() it doesn't seem to be reading the row ID field at all. I can't get ...
- [FEATURE] Better usage analytics for app...
Recently, i've gotten **73** emails from appwrite regarding excesive GBHours usage. I've almost hit the limit of 1000 and it is really hard to track down which ...
- Permissions in create_operations() Pytho...
How can I set permissions for `create_operations()`? What even is the correct way to use permissions in Python (using SDK version 13.4.1) ? In my cloud functio...
