Sometimes I end up in a situation when the desktop environment does not work...
That happened recently, and I had to search again how to connect to wifi from the terminal.
Below is what I did:
ifconfig # to see the interface, in my case it was wlp4s0
nmcli d connect wlp4s0 --ask # to connect to my saved wifi connection (it will ask for a password)