UTI while pregnant 1ts trimester

Maria • Expecting baby #2
Okay so I'm 8weeks and like a day or two. I went to the hospital yesterday because of some pain and they told me i have a uti. Is it safe to drink the medicine while pregnant? The doctor said yea but is my first baby i want be sure. Thank you.