Fix KeyErrors

Fig bug where if a branch new client connects with a new device ID, the
database lookup fails. Fix KeyError on disconnect if client disconnects before
logging in.
Sending keys and logging out now websocket friendly