- Add authentication middleware to protect routes - Create API endpoints for login, logout, registration, and user info - Develop UI components for login and registration forms - Integrate VeeValidate for form validation - Update environment configuration for Cidaas settings - Add i18n support for English and German languages - Enhance Tailwind CSS for improved styling of auth components - Document authentication flow and testing procedures
29 lines
572 B
TypeScript
29 lines
572 B
TypeScript
// middleware/auth.ts
|
|
|
|
/**
|
|
* Authentication middleware
|
|
*
|
|
* Protects routes from unauthenticated access
|
|
*
|
|
* Usage in pages:
|
|
*
|
|
* definePageMeta({
|
|
* middleware: 'auth'
|
|
* })
|
|
*/
|
|
|
|
export default defineNuxtRouteMiddleware(async (to, from) => {
|
|
const { loggedIn } = useUserSession()
|
|
|
|
// Not logged in - redirect to auth page
|
|
if (!loggedIn.value) {
|
|
// Store intended destination for post-login redirect
|
|
useCookie('redirect_after_login', {
|
|
maxAge: 600, // 10 minutes
|
|
path: '/',
|
|
}).value = to.fullPath
|
|
|
|
return navigateTo('/auth')
|
|
}
|
|
})
|