
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
- Why "You’ve reached the limit for your G...
Why did Appwrite send me this alert when the usage reached 10605%? Is it too late? Why not when reached 100% usage? And I can not pay for more usage described ...
- Subdomain failed verification
So I wanted to do a custom subdomain, because local storage doesn't work for me, but I've tried it a long time ago, it didn't work for me, and now I'm trying ag...
- Sites 30MB limit from GitHub
I’m deploying a site from github as Other type on the Hobby plan. It is actually a Flutter web app but it’s in a subdirectory with the root being an html landin...
