diff --git a/discovery-provider/src/utils/auth_middleware.py b/discovery-provider/src/utils/auth_middleware.py index 3146ec78795..6b16463aad0 100644 --- a/discovery-provider/src/utils/auth_middleware.py +++ b/discovery-provider/src/utils/auth_middleware.py @@ -1,10 +1,13 @@ import functools +import logging from eth_account.messages import encode_defunct from flask.globals import request from src.models.models import User from src.utils import db_session, web3_provider +logger = logging.getLogger(__name__) + MESSAGE_HEADER = "Encoded-Data-Message" SIGNATURE_HEADER = "Encoded-Data-Signature" @@ -50,10 +53,16 @@ def inner_wrap(*args, **kwargs): User.wallet == wallet.lower(), User.is_current == True, ) + # In the case that multiple wallets match (not enforced on the data layer), + # pick the user id that is lowest (created first). + .order_by(User.user_id.asc()) .first() ) if user: authed_user_id = user.user_id + logger.info( + f"auth_middleware.py | authed_user_id: {authed_user_id}" + ) return func(*args, **kwargs, authed_user_id=authed_user_id) return inner_wrap