Fix authentication by moving the check upwards.