implemented authentication middleware