Refactor out pattern matching from auth checks.