diff --git a/web/routes/evotor_webhooks.py b/web/routes/evotor_webhooks.py index 9154af9..5f8439e 100644 --- a/web/routes/evotor_webhooks.py +++ b/web/routes/evotor_webhooks.py @@ -63,13 +63,18 @@ def _upsert_evotor_connection( """Create or update an evotor_connections row; always regenerates api_token.""" api_token = secrets.token_urlsafe(32) conn = db.query(EvotorConnection).filter( - EvotorConnection.evotor_user_id == evotor_user_id + or_( + EvotorConnection.evotor_user_id == evotor_user_id, + EvotorConnection.user_id == user_id, + ) ).first() now = datetime.now(timezone.utc).replace(tzinfo=None) if conn: conn.api_token = api_token if user_id is not None: conn.user_id = user_id + if evotor_user_id: + conn.evotor_user_id = evotor_user_id if access_token: conn.access_token = access_token conn.updated_at = now