import type { HttpContext } from '@adonisjs/core/http' import type { NextFn } from '@adonisjs/core/types/http' /** * AuthSessionMiddleware * * Protects web-ui routes by requiring an authenticated session. * If the session is not authenticated, stores the requested URL * in the session and redirects to /login. * * Login is handled by AuthController + session-based authentication. */ export default class AuthSessionMiddleware { async handle({ session, request, response }: HttpContext, next: NextFn) { if (!session.get('authenticated')) { // Remember where the user wanted to go if (request.method() === 'GET') { session.put('redirectAfterLogin', request.url()) } return response.redirect().toPath('/login') } return next() } }