Added automatic re-login if the session has timed out.

fixes #1058