gold eggs backend
Some checks failed
Build and Push to Docker Hub / build-test-push (push) Failing after 1m55s

This commit is contained in:
2026-04-15 08:59:36 +02:00
commit ab73d05ecc
359 changed files with 14415 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import jwt
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
from core.http.models import User
class JWTFCMMiddleware(MiddlewareMixin):
def process_request(self, request):
auth_header = request.headers.get("Authorization")
if auth_header and auth_header.startswith("Bearer "):
token = auth_header.split(" ")[1]
try:
payload = jwt.decode(
token, settings.SECRET_KEY, algorithms=["HS256"]
)
user_id = payload.get("user_id")
fcm_token = request.headers.get("FCM-Token")
if user_id:
user = User.objects.get(id=user_id)
if fcm_token:
user.fcm_token = fcm_token
user.save()
except jwt.ExpiredSignatureError:
pass
except jwt.InvalidTokenError:
pass