from django.utils.deprecation import MiddlewareMixin

from django.conf import settings


class ExpiredSessionMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        if request.user.is_superuser == True:
            max_age = None
            expires = None
            response.set_cookie(
                settings.SESSION_COOKIE_NAME,
                request.session.session_key,
                max_age=max_age,
                expires=expires,
                domain=settings.SESSION_COOKIE_DOMAIN,
                path=settings.SESSION_COOKIE_PATH,
                secure=settings.SESSION_COOKIE_SECURE or None,
                httponly=settings.SESSION_COOKIE_HTTPONLY or None,
                samesite=settings.SESSION_COOKIE_SAMESITE,
            )

        return response
