Revert "Revert to main branch account handling logic"
This reverts commit 219dae83c6.
This commit is contained in:
@@ -99,13 +99,14 @@ class AccountContextMiddleware(MiddlewareMixin):
|
||||
user = User.objects.select_related('account', 'account__plan').get(id=user_id)
|
||||
request.user = user
|
||||
if account_id:
|
||||
# Verify account still exists and matches user
|
||||
account = Account.objects.get(id=account_id)
|
||||
# If user's account changed, use the new one from user object
|
||||
if user.account and user.account.id != account_id:
|
||||
request.account = user.account
|
||||
else:
|
||||
# Unified API Standard: Extract account_id from JWT, load Account object, set request.account
|
||||
# Token's account_id is authoritative - no validation against user.account
|
||||
try:
|
||||
account = Account.objects.get(id=account_id)
|
||||
request.account = account
|
||||
except Account.DoesNotExist:
|
||||
# Account from token doesn't exist - set to None
|
||||
request.account = None
|
||||
else:
|
||||
try:
|
||||
user_account = getattr(user, 'account', None)
|
||||
|
||||
Reference in New Issue
Block a user