Fixed login/register middleware