Adding an outlet to a switch box
The proper way to do this would be to replace the 14/2 or 12/2 with a 14,12/3 cable. At the ceiling connect your new black to hot, new white to existing white and white from light fixture, and red to the black from the light. At the switch box, pigtail hot to brass screw of outlet and to top of switch or follow directions on box if using combination switch/outlet. Connect white to silver screw on outlet and red wire to bottom of switch or follow directions if using combination switch/outlet. Don't use any backstabs if present. Turn off breaker before doing any work.