fixing authentication race condition