About the first fact see [this][1] page (the Krull–Remak–Schmidt theorem). For infinite (even finitely generated) groups the situation is different because there exists an infinite f.g. group isomorphic to its [direct square.][2]

**Update.** [Hirshon][3], found two non-isomorphic finitely generated nilpotent (infinite) groups $G,H$ such that $G\times G\cong H\times H$. 


  [1]: https://groupprops.subwiki.org/wiki/Direct_product_is_cancellative_for_finite_groups
  [2]: https://groupprops.subwiki.org/wiki/Group_isomorphic_to_its_square
  [3]: https://doi.org/10.1007/BF01229716 "Hirshon, R. The cancellation of an infinite cyclic group in direct products. Arch. Math 26, 134–138 (1975). zbMATH review at https://zbmath.org/?q=an:0303.20022"