Moved auth logic to a common module.