diff --git a/backend/app/api/auth.py b/backend/app/api/auth.py index 6ac573f9..499f3457 100644 --- a/backend/app/api/auth.py +++ b/backend/app/api/auth.py @@ -79,8 +79,12 @@ def register(data: dict, db: Session = Depends(get_db)): ) db.add(user) db.commit() - # 新用户默认授予所有active企业 - _ensure_default_grants(db, user.id) + db.refresh(user) + # 注册默认授权第一个active企业(不授予全部,保证账套隔离) + first_ent = db.query(Entity).filter(Entity.status == "active").order_by(Entity.id).first() + if first_ent: + db.add(UserEntity(user_id=user.id, entity_id=first_ent.id)) + db.commit() return {"message": "注册成功"}