Smooth login flow by adding logic to template, including error display