Fixed a KeyError on login with legacy sessions; refs #21649.

Thanks Loic for the report.