Refactor database connection in auth utility.