Technically, it is not legal for someone to patent your invention:
"The patent application includes a declaration in which the applicant swears that everything in the application is true. So if you falsely claim that you invented something when you did not, that would amount to fraud on the U.S. Patent and Trademark Office which would result in a termination of any rights you may have obtained (along with possible sanctions). Second, your theft of the idea (referred to as misappropriation) may result in a separate lawsuit against you by the real inventor. That lawsuit may be based on different claims depending on your relationship with the real inventor -- for example, whether you had a confidential relationship with the actual inventor. In general theft of ideas is a dangerous game and one that usually backfires professionally and financially."
- The direct answer is you've have to take them to take them to court and sue them. You'd need to prove that they did indeed steal your invention. To that end, you should save any correspondence (email, text, etc.) you have with relevant information. You would definitely want to consult an attorney on how specifically to proceed. Consultations are generally free.
The problem is that patent litigation is generally ruinously expensive, so most parties will choose to settle.
If the invention makes a great deal of money, there are attorneys who will work on a straight contingency basis for a big cut of the award or settlement. [Note that the idea that most parties settle can work in your favor here—those "ruinous costs" apply equally to the alleged thief.]
Right now, every country in the world uses the "First to File" rule. (The US was the last holdout and only switched over in 2013.) This means that if multiple inventors have the same idea, the one who files first has the right to the patent. Obviously, this circumstance would also seem to open the door to the type of fraud you're experiencing.
In future, you may want to consider filing provisional patents before discussing ideas you believe in. Provisional patents may be filed very inexpensively and do not require a lawyer--you just have to get the ideas down on paper and make sure it is understandable. This then gives you a full year to decide whether to take on the expense of pursuing an non-provisional (formal) filing.