TorbatYar/frontend/app/auth/callback/page.tsx
Mortezakoohjani 800b0ba2c5 Deploy TorbatYar for torbatyar.ir with nginx multi-tenant routing.
Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-21 21:43:33 +03:30

69 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import {
exchangeCode,
consumePostLoginRedirect,
fetchAuthConfig,
fetchMe,
redeemHandoff,
storeTokens,
} from "@/lib/auth";
import { useRouter, useSearchParams } from "next/navigation";
import { Suspense, useEffect, useRef, useState } from "react";
function CallbackInner() {
const params = useSearchParams();
const router = useRouter();
const [error, setError] = useState<string | null>(null);
const exchangeStarted = useRef(false);
useEffect(() => {
if (exchangeStarted.current) return;
const handoff = params.get("handoff");
const code = params.get("code");
if (!handoff && !code) {
setError("کد احراز هویت دریافت نشد");
return;
}
exchangeStarted.current = true;
(async () => {
try {
let tokens;
if (handoff) {
tokens = await redeemHandoff(handoff);
} else {
const config = await fetchAuthConfig();
tokens = await exchangeCode(code!, config.callback_url, params.get("state"));
}
storeTokens(tokens);
const me = await fetchMe(tokens.access_token);
if (me.requires_mobile_verification) {
router.replace("/auth/verify-mobile");
return;
}
router.replace(consumePostLoginRedirect("/dashboard"));
} catch (e) {
exchangeStarted.current = false;
setError(e instanceof Error ? e.message : "خطای ناشناخته");
}
})();
}, [params, router]);
if (error) {
return <p className="mt-8 text-red-600">{error}</p>;
}
return <p className="mt-8 text-gray-600">در حال تکمیل ورود...</p>;
}
export default function AuthCallbackPage() {
return (
<Suspense fallback={<p className="mt-8">...</p>}>
<CallbackInner />
</Suspense>
);
}