One of the first inhumane and racially tinged acts of the Trump administration was to close the borders to travelers from seven Muslim-majority nations for 90 days and to global refugees for 120 days (except Syrian refugees, who were banned indefinitely). These moves were all in an effort, President Trump said, “to protect the American people from terrorist attacks by foreign nationals admitted to the United States.”

It took him three tries over 17 months to finally broaden the entry ban sufficiently for the Supreme Court to let it stand despite the clear anti-Muslim intent — Trump said during the campaign that he wanted a “total and complete shutdown of Muslims” — and the administration’s legal dodges to achieve it.

Lost in the debate was the issue of how the president had such power in the first place. It’s because Congress gave it to him. Federal law gives the president significant leeway to develop rules and regulations on how the immigration system should work, including wide latitude on deciding who can enter the country.

In delegating such authority to the president, Congress assumed the elected chief executive would have the nation’s best interests at heart, would respect the democratic institutions that make government work, and would not base policies on a foundation of racial and religious animus. Well, Trump exposed the dangerous repercussions from that mistaken presumption.

On Wednesday, the House began trying to wrest back some power by passing the No Ban Act, a bill by Rep. Judy Chu (D-Monterey Park) to bar a president from banning entry on the basis of religion. The proposal also would restrict temporary bans to those that “address specific acts implicating a compelling government interest” in protecting “the security or public safety of the United States or the preservation of human rights, democratic processes or institutions, or international stability.”

Any restriction must be narrowly tailored, and the president also would have to first consult with Congress, then deliver a follow-up report within 48 hours or the ban would expire. And the bill would allow people unlawfully harmed by such a restriction to sue in federal court, a recourse not often available under existing immigration law.

Those are sound steps that boil down to Congress clarifying what powers it wants to give the executive in this section of immigration law, while making it more difficult for a rogue president to concoct another variation of a Muslim ban in the future. The sad part is that such a legal restriction is even necessary. Early indications are the measure faces an uphill fight in the Senate, but its members ought to join the House and send it along to President Biden, who has voiced support for the proposal.

And Congress should not stop there. Trump taught us many things about the weaknesses in some of our democratic institutions, including the fact that the executive branch has, over the decades, knocked the balance of powers off kilter. In a sense, Trump merely accelerated the ongoing shift in power from an increasingly dysfunctional Congress to a president willing to act unilaterally. This isn’t about liberal versus conservative views on specific issues so much as it is about the legislative branch trimming the sails of the executive branch.

One target for lawmakers should be the National Emergencies Act of 1976, which sets the circumstances under which the president can use a broad array of heightened powers granted by Congress. The point was to enable the president to tackle problems that needed a faster or more flexible response than the legislative process could provide. But the act contains a significant loophole that Trump exploited: Unable to persuade Congress to fund his border wall, he declared an emergency to give himself the power to build the wall anyway. Congress can end such a declaration, but that is subject to a presidential veto, which requires a two-thirds vote in each chamber to override.

That’s way too much power for the executive. Congress should look to revise the law to return more oversight power to the legislative branch.

The wall fight is just one example of the ways Trump, who functioned as a human stress test on the checks and balances in our system, sought to circumvent the requirements of Congress and federal law. Happily, many of his administration’s efforts to rewrite or ignore the rules ran afoul of the Administrative Procedure Act, which spells out what steps the executive branch must take in crafting regulations to implement laws. In fact, the Trump administration’s routine failure to follow the APA could well have saved the country from the worst excesses of his anti-regulatory agenda, particularly in his rollback of environmental protections.

The firewall provided by the APA is merely procedural, however, so it may not curb a power-grabbing administration that carefully dots its I’s and crosses its Ts. Congress ought to take a wholesale look at the holes and weaknesses Trump exposed (and exploited) in our system of governance and come up with fixes, lest we run afoul of the old warning that those who don’t learn from the past are doomed to repeat it.