refactor the client and add lonin check function on server