Refactor auth and add support for second factor