Updated authentication middleware