fix(oauth): add callback error page for google oauth flow
Some checks failed
Frontend CI/CD / build (push) Has been cancelled
Frontend CI/CD / deploy (push) Has been cancelled

This commit is contained in:
2026-05-22 00:59:19 +03:30
parent dbc0ebb118
commit 065360b7a8
3 changed files with 33 additions and 1 deletions

View File

@@ -34,6 +34,8 @@ export default function GoogleAuthCallback() {
const isRtl = lang === "fa";
const flow = searchParams.get("flow") ?? "";
const callbackErrorCode = searchParams.get("error") ?? "";
const callbackErrorDescription = searchParams.get("error_description") ?? "";
const [step, setStep] = useState<GoogleStep>("loading");
const [loading, setLoading] = useState(false);
@@ -50,6 +52,22 @@ export default function GoogleAuthCallback() {
otpVerify: 0,
});
const resolveCallbackErrorMessage = () => {
if (callbackErrorCode === "access_denied") {
return t.login.google.cancelled;
}
if (callbackErrorDescription) {
if (callbackErrorDescription === "Google token exchange failed.") {
return t.login.google.tokenExchangeFailed;
}
if (callbackErrorDescription === "Google user profile lookup failed.") {
return t.login.google.profileLookupFailed;
}
return callbackErrorDescription;
}
return t.login.google.callbackFailed;
};
useEffect(() => {
if (!Object.values(cooldowns).some((value) => value > 0)) {
return;
@@ -138,6 +156,12 @@ export default function GoogleAuthCallback() {
};
useEffect(() => {
if (callbackErrorCode) {
setErrorMessage(resolveCallbackErrorMessage());
setStep("error");
return;
}
if (!flow) {
setErrorMessage(t.login.google.missingFlow);
setStep("error");
@@ -170,7 +194,7 @@ export default function GoogleAuthCallback() {
return () => {
cancelled = true;
};
}, [flow]);
}, [callbackErrorCode, callbackErrorDescription, flow, lang]);
const handleCompleteSignup = async (event: React.FormEvent) => {
event.preventDefault();