Tolkien lived through WW2.
Which he used as inspiration for how the nations would react to a great catastrophe.
I think this, along with most of the comments in this thread, is oversimplistic and does Tolkien and his work a pretty serious disservice.
Tolkien was an academic, a student of myth. The reason his works are some of the best-selling books ever written, and that they still resonate with people so strongly seventy-five years later, is not because LOTR is a gritty take on the realities of trench warfare - it’s because Tolkien understood, possibly better than anyone else ever has, feelings, experiences, and tropes that are timeless, ideas that are innate to the human experience.
Everyone saying “Tolkien based LOTR on his experiences in WWI” is entirely missing the fact that Tolkien was attempting to create a mythology. Mythical stories across the world throughout history, from the Bible to Germanic sagas, to Finnish myth, to Greek myth, to middle-eastern myths, feature similar tropes of “not acting until it’s almost too late”, and I honestly think it’s insulting to ignore the fact that Tolkien was tapping into his vast understanding of myth to distill truths about the human experience that have nearly universal appeal, only to instead put him into a shallow box of “he wuz riting about Worl War I/II/nuclear bombs/whatevs lol”.
Did those experiences factor into his Middle Earth writings? Of course they did, but it’s still badly missing the point to claim that his works are allegorical as a result. That’s why Tolkien always reacted so strongly when people accused him of allegory - it’s, frankly, an insult, and a complete misunderstanding of the point of Tolkien’s work in the first place.
WW1*
Tolkien was a soldier in WW1 and his experience as a soldier would have had an effect on his writing, especially considering the Lord of the Rings books were written before and during WW2, which he’s also denied had any influence on them.