Unfortunately, this is a nasty little problem a lot of people new to lucid dreaming experience, and a lot of experienced lucid dreamers still do! I've had 47 and I still sometimes wake up immediately after gaining lucidity

There are a few things that you can do to stop this, you have to Flood Your Senses: The theory behind this is that if your brain is so busy creating dream senses, it won't be able to sense things like the feeling of your pillow or the sound of your fan or whatever is in the real world. If you focus on those sensations, likely you will wake up. So instead, you should do things like rub your hands to get that tactile feeling, try sniffing the air and listening for sounds and speaking out loud. You can even try eating things to see what they taste like, remember you can eat anything in a dream and it's actually fun!

I often find that looking down at my own dream body, talking to myself or to dream characters, and just looking at and touching objects in my dreams can really help. And not only do these things help stabilize a dream, but they are also fun lucid experiences all on their own!

That said, the more experience you get the better you will be at remaining in the dream. Good luck!