Preheat the oven to 400°F and grease a 9×13-inch baking dish with butter.
In a medium skillet, melt the butter over medium heat.
Add the flour and whisk for about 1 minute to cook out the raw flour taste.
Slowly pour in the milk while whisking continuously to keep the sauce smooth.
Add the vegetable broth and continue whisking until the sauce begins to thicken.
Stir in the grated garlic, thyme, salt, and black pepper.
Cook the sauce for about 2 to 3 minutes until it lightly coats the back of a spoon.
Remove the skillet from the heat.
Layer half of the sliced potatoes evenly in the prepared baking dish.
Add half of the sliced onions on top of the potatoes.
Pour half of the sauce over the layer and sprinkle 1 cup of cheese.
Repeat the layers with the remaining potatoes, onions, sauce, and the remaining ½ cup cheese.
Cover the dish and bake for 30 minutes.
Remove the cover and continue baking for 35 to 40 minutes until the potatoes are tender and the top is golden brown.
Let the dish rest at room temperature for about 20 minutes before serving.