chore: fix OAuth callback double-run state error
This commit is contained in:
parent
d14cfa1c4f
commit
b8029c70ef
1 changed files with 6 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
import { timestampDate } from "@bufbuild/protobuf/wkt";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from "react-router-dom";
|
||||||
import { setAccessToken } from "@/auth-state";
|
import { setAccessToken } from "@/auth-state";
|
||||||
import { authServiceClient } from "@/connect";
|
import { authServiceClient } from "@/connect";
|
||||||
|
|
@ -18,12 +18,17 @@ const AuthCallback = () => {
|
||||||
const navigateTo = useNavigateTo();
|
const navigateTo = useNavigateTo();
|
||||||
const { initialize } = useAuth();
|
const { initialize } = useAuth();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
const handledRef = useRef(false);
|
||||||
const [state, setState] = useState<State>({
|
const [state, setState] = useState<State>({
|
||||||
loading: true,
|
loading: true,
|
||||||
errorMessage: "",
|
errorMessage: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (handledRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handledRef.current = true;
|
||||||
// Check for OAuth error response first (e.g., user denied access)
|
// Check for OAuth error response first (e.g., user denied access)
|
||||||
const error = searchParams.get("error");
|
const error = searchParams.get("error");
|
||||||
const errorDescription = searchParams.get("error_description");
|
const errorDescription = searchParams.get("error_description");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue