Rename KYC models (Application/Profile) and add public schema with MongoDB
All checks were successful
Build Docker Image / build (push) Successful in 3m7s
All checks were successful
Build Docker Image / build (push) Successful in 3m7s
This commit is contained in:
@@ -13,3 +13,37 @@ class UserGraphQLView(GraphQLView):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['middleware'] = [UserJWTMiddleware()]
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class M2MGraphQLView(GraphQLView):
|
||||
"""M2M endpoint - no authentication (internal network only)."""
|
||||
pass
|
||||
|
||||
|
||||
class OptionalUserJWTMiddleware:
|
||||
"""Middleware that optionally extracts user_id but doesn't fail if missing."""
|
||||
|
||||
def resolve(self, next, root, info, **args):
|
||||
request = info.context
|
||||
|
||||
# Try to extract user_id from Authorization header if present
|
||||
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
|
||||
if auth_header.startswith('Bearer '):
|
||||
try:
|
||||
from .auth import validate_jwt_token
|
||||
token = auth_header.split(' ', 1)[1]
|
||||
payload = validate_jwt_token(token)
|
||||
if payload:
|
||||
request.user_id = payload.get('sub')
|
||||
except Exception:
|
||||
pass # Ignore auth errors - user just won't get full data
|
||||
|
||||
return next(root, info, **args)
|
||||
|
||||
|
||||
class PublicGraphQLView(GraphQLView):
|
||||
"""Public endpoint - optional auth for full data, no auth for teaser."""
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Use optional auth middleware that doesn't fail on missing token
|
||||
kwargs['middleware'] = [OptionalUserJWTMiddleware()]
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user