Does anyone have an example of a function they use to authenticate a user and if they have permission to access the current page?
The function would run on page load, or in a reusable component like a navigation bar, and:
- Check if a user is logged in, if not redirect to login page
- Check if a user has permission to access this page, if not redirect to a 401 page.
- The permission system could be hardcoded in the function for a small app or in a table/json/etc. for a larger app.