Remove duplication in auth handler.
Extract namespace logic into a module.