chore: fix OAuth callback double-run state error

This commit is contained in:
Steven 2026-02-02 09:07:55 +08:00
parent d14cfa1c4f
commit b8029c70ef
1 changed files with 6 additions and 1 deletions

View File

@ -1,5 +1,5 @@
import { timestampDate } from "@bufbuild/protobuf/wkt";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { useSearchParams } from "react-router-dom";
import { setAccessToken } from "@/auth-state";
import { authServiceClient } from "@/connect";
@ -18,12 +18,17 @@ const AuthCallback = () => {
const navigateTo = useNavigateTo();
const { initialize } = useAuth();
const [searchParams] = useSearchParams();
const handledRef = useRef(false);
const [state, setState] = useState<State>({
loading: true,
errorMessage: "",
});
useEffect(() => {
if (handledRef.current) {
return;
}
handledRef.current = true;
// Check for OAuth error response first (e.g., user denied access)
const error = searchParams.get("error");
const errorDescription = searchParams.get("error_description");