Skip to content

Instantly share code, notes, and snippets.

@J-Priebe
J-Priebe / jwt_middleware.py
Last active January 17, 2024 15:31
Cookie-based JWT Middleware for Django Channels
from django.contrib.auth.models import AnonymousUser
from django.db import close_old_connections
from django.conf import settings
from channels.sessions import CookieMiddleware
from channels.db import database_sync_to_async
from rest_framework_simplejwt.authentication import JWTAuthentication
import logging
logger = logging.getLogger(__name__)