fix(oauth): add callback error page for google oauth flow
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user