Middlewares
The Login and Registration feature includes a global authentication guard implemented as a route middleware to manage user authentication and access control. It ensures that users are correctly redirected based on their authentication status and role while handling route protection and URL redirections dynamically.
authGuard.global.ts
The global Nuxt route middleware handles route protection and access for each user role and redirection URL. It covers the following cases:
- Unauthorized access to protected routes: If a user is not logged in and tries to access a protected route, they are redirected to the sign-in page.
- Preserving redirect URLs: If a user who is not logged in tries to access the sign-in page from any other page (excluding the sign-in page itself), the previous route is stored as a redirect URL.
- Preventing redundant sign-in attempts: If logged-in users try to access the sign-in page, they are redirected to the home page instead.
- Guest user restrictions: If a guest user tries to access any page except checkout, they are redirected to either the predefined redirect URL or the home page.
- Handling missing configurations: No redirection is performed if neither a shop nor an API route is detected.