I recently took off a light fixture in my home's bathroom and before I could take mental note of the wiring situation, the white wire from the fixture slipped from a wire nut (not a great sign of previous electrical work, I know..). The black wire from the fixture was connected to the single black wire on the right side of the box (presumably the switch's cable) but I do not know where the fixture's white wire was connected. I have a feeling the white wire from the fixture was connected to the two black wires on the left side of the picture, however, I'm hesitant to do that (I added the electrical tape for now). Note that the fixture/switch were working perfectly fine. Any thoughts on where the white wire from the fixture needs to be attached? Thanks in advance
What you've got here is power in to the fixture box, power out to whatever is next and a "switch leg" cable to the switch. You are probably right that the wires from the fixture were connected to the blacks with the wire nuts. Unfortunately this isn't best practice, dangerous at best. This setup leaves the fixture "hot" all the time and effectively interrupts the neutral.
The way to make it right is to connect the right black wire with the 2 on the left. Disconnect the white wires and code tape black the white wire coming back from the switch. Connect that to the black wire on the fixture and the other wire (white) from the fixture to the other white wires. Best practice would be pigtail the whites so you only have one wire to deal with when installing the fixture.
Oh and get a wire nut on those ground wires while you're in there!
Hook the white wire from the fixture to the group of white wires under the red wire nut. The black wire from the fixture goes to the single black wire in the box. It appears that the person who originally wired this used two 12-2 instead of a 12-3 going from the fixture to the switch. I think the NEC frowns on this.
OK, if this is a switch loop, then forget this and go see George's answer. My first thoughts were an attempt to get hot and neutral at the switch location and to switch the light. A picture of the switch box would clarify this.