With a firearm you have the advantage of the loud noise too. Which may or may not help.
Actually I’ve used bear spray once, in the case of a black bear sow with two cubs. She seemed more curious than aggressive. I pulled the trigger on the spray can to make sure it was going to work and the noise the blast made scared her away.
When I’m in bear country I always carry spray and a big revolver. The one I use first will depend on the situation. I don’t understand why so many people get hung up on arguing about this like it’s a one or the other thing. A can of bear spray weighs as much as a small water bottle. Not a big thing to strap on the belt of a backpack.