Fix authentication logic