fix poor handling of error during login

Fixes a panic that was reported when err was nil here.