Move auth logic from ai-services