Handling login error and redirect on successful login