Fix authentication bugs and add logout method