Modularized authentication code & added logout functionality on server-side.