Implemented logout and authentication middleware