Was the NATO Invasion of Afghanistan Legal?

Despite the US’ claims of self-defence and terrorist eradication, it can be argued that the NATO invasion of Afghanistan in October 2001 was not legal under international law.