Moved auth logic to its own module