Still more fixes to auth middleware and base functionality.