I'm wondering what the best practice is for handling redirects when a user accesses a page where they're not authenticated. At the moment, I have an API call set in my site header that does a GET request to get the logged in user profile (profiles table). If the user does not have an access token obviously no data is returned but the request still returns a status of 200 and an empty array is returned, which indicates partial success but no data is available due to the RLS policy for the table.
This means that no error is returned in order to handle redirect to another page e.g. /login, so I'm wondering what the best approach might be to handle this.
Similarly, when a user session expires, users can still access application pages but no data is returned due to RLS policies in place. For testing and development this is okay but I'd obviously look to lock this down and auto-redirect on session expiry so that access to the page is no longer possible and the user is redirected to /login.
Does anyone have any pointers on how best to handle these scenarios?