Which state to pay taxes in

My wife and I sold our home in New Jersey and moved to New York City in 2021.  To finance the purchase of our new Condo we sold some of our investments in stocks.  This occurred while we were still living in New Jersey.  At the end of the year our legal residence is New York.  My question is do I owe taxes on the capital gains to New Jersey,  New York, or both?