I'm having trouble with the system UI not loading after login. A few days ago I restarted my computer and got the login screen as expected, clicked on my user, typed my password and the UI did not load, got a black screen. Then I pressed the shutdown button for 10 seconds to force a restart, got the login screen back, typed my password, got same black screen. Repeated this process for like 5 more times and got the same thing. Then out of frustration I was like I'm going to wait the black screen for a while, waited in the black screen for around 30 minutes, nothing happened.
Then I unplugged my HDMI cable that connect to my second monitor to test if that could be the problem. Still same thing, after login I got a black screen. I restarted it again a few more times and same error. So in a lucky move (lucky because I was leaning towards format whole thing and install ubuntu again), in the login screen, I connected my HDMI cable before typing my password...then typed password, pressed enter and voila: Ubuntu UI was on.
So today, this problem happened again, I had to restart my computer to apply a Ubuntu update, after restart I got the login screen, typed my password and black screen. I pressed the shutdown button for 10 seconds to force and restart, in the login screen I got into terminal (ctrl+alt+F3) to see some settings, I was getting error like: xhost unable to open display. Searching online got some info to see $DISPLAY variable, echo $DISPLAY did show nothing was set, I tried setting it to :0, :0.0 and :1, neither worked. Also tried the command who that did show my user and tty1 in front of it. I tried to set $DISPLAY to tty1 and still same error xhost unable to open display. Other things I tried was to reinstall ubuntu-desktop, sudo apt install --reinstall ubuntu-desktop which also did not work. After some time and nothing works, I shut it down again plugged my HDMI in the login screen, typed my password and UI works.
So anyone could help me understand what is happening here, what I can do to stop this problem, because looks like If I don't have a HDMI cable close to me this notebook will not work at all. This behavior started 1 week ago. Also worth mentioning that I'm not that experienced with Ubuntu and the terminal at all.
Ubuntu version: 22.04.3 LTS
OS Type: 64bit
GNOME version: 42.9