updeted login methd to include error handling