Move db auth logic to its own module