refactoring of authentication