Description:
We need to add a middleware to protect authenticated routes in the AssetsUp frontend. The middleware should check if a user is authenticated before granting access to restricted routes (e.g., /dashboard, /assets, /departments). If the user is not authenticated, they should be redirected to the /login page.
This will ensure that unauthorized users cannot directly access protected pages via URL.
Tasks:
- Create a
middleware.ts file in the project root.
- Configure the middleware to run only on specific protected routes (
/dashboard, /assets, /departments, etc.).
- Implement logic to check authentication tokens (from cookies, headers, or local storage).
- Redirect unauthenticated users to
/login.
- Allow public routes (e.g.,
/, /login, /register) to bypass the middleware.
- Add TypeScript typings for request/response handling.
- Write documentation (
docs/auth-middleware.md) explaining how the middleware works and how to extend it for new protected routes.
Acceptance Criteria:
- Visiting
/dashboard while not logged in redirects to /login.
- Visiting
/assets while authenticated loads successfully.
- Public routes (
/, /login, /register) remain accessible to everyone.
- Middleware logic is reusable and easy to extend for future routes.
Description:
We need to add a middleware to protect authenticated routes in the AssetsUp frontend. The middleware should check if a user is authenticated before granting access to restricted routes (e.g.,
/dashboard,/assets,/departments). If the user is not authenticated, they should be redirected to the/loginpage.This will ensure that unauthorized users cannot directly access protected pages via URL.
Tasks:
middleware.tsfile in the project root./dashboard,/assets,/departments, etc.)./login./,/login,/register) to bypass the middleware.docs/auth-middleware.md) explaining how the middleware works and how to extend it for new protected routes.Acceptance Criteria:
/dashboardwhile not logged in redirects to/login./assetswhile authenticated loads successfully./,/login,/register) remain accessible to everyone.