Fix Clerk custom domain URL generation

- Support custom domains like clerk.yargimcp.com
- Auto-detect between custom domains and standard .accounts.dev subdomains
- Apply fix to both main OAuth and Google OAuth flows
- Maintain backward compatibility with standard Clerk domains

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
saidsurucu
2025-07-02 00:50:25 +03:00
co-authored by Claude
parent 6919ac552b
commit 9880316fd2
+19
View File
@@ -95,7 +95,17 @@ async def oauth_login(request: Request, redirect_uri: Optional[str] = None):
domain = os.getenv("CLERK_DOMAIN", "localhost") domain = os.getenv("CLERK_DOMAIN", "localhost")
# Production Clerk hosted sign-in URL # Production Clerk hosted sign-in URL
# Check if domain already includes full URL or just subdomain
if domain.startswith('http'):
# Full URL provided
clerk_sign_in_url = f"{domain}/sign-in"
elif '.' in domain and not domain.endswith('.accounts.dev'):
# Custom domain like clerk.yargimcp.com
clerk_sign_in_url = f"https://{domain}/sign-in"
else:
# Standard Clerk subdomain
clerk_sign_in_url = f"https://{domain}.accounts.dev/sign-in" clerk_sign_in_url = f"https://{domain}.accounts.dev/sign-in"
oauth_url = f"{clerk_sign_in_url}?{urlencode(clerk_oauth_params)}" oauth_url = f"{clerk_sign_in_url}?{urlencode(clerk_oauth_params)}"
logger.info(f"Redirecting to Clerk OAuth: {oauth_url}") logger.info(f"Redirecting to Clerk OAuth: {oauth_url}")
@@ -383,6 +393,15 @@ async def google_oauth_login(request: Request):
domain = os.getenv("CLERK_DOMAIN", "localhost") domain = os.getenv("CLERK_DOMAIN", "localhost")
# Build Clerk sign-in URL with Google as the provider # Build Clerk sign-in URL with Google as the provider
# Check if domain already includes full URL or just subdomain
if domain.startswith('http'):
# Full URL provided
google_oauth_url = f"{domain}/sign-in#/?strategy=oauth_google"
elif '.' in domain and not domain.endswith('.accounts.dev'):
# Custom domain like clerk.yargimcp.com
google_oauth_url = f"https://{domain}/sign-in#/?strategy=oauth_google"
else:
# Standard Clerk subdomain
google_oauth_url = f"https://{domain}.accounts.dev/sign-in#/?strategy=oauth_google" google_oauth_url = f"https://{domain}.accounts.dev/sign-in#/?strategy=oauth_google"
return RedirectResponse(url=google_oauth_url) return RedirectResponse(url=google_oauth_url)