mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-04 13:22:41 +02:00
refactor: migrate OAuth result handling from sessionStorage to cookies and update connector callback implementation
- Removed the ConnectorCallbackPage component and replaced it with a route handler that sets the OAuth result in a cookie. - Updated the useConnectorDialog hook to read from the cookie instead of sessionStorage, ensuring a more consistent state management approach.
This commit is contained in:
parent
8baba0693d
commit
95f11521c3
3 changed files with 52 additions and 38 deletions
|
|
@ -40,7 +40,19 @@ import {
|
|||
validateIndexingConfigState,
|
||||
} from "../constants/connector-popup.schemas";
|
||||
|
||||
const OAUTH_RESULT_KEY = "connector_oauth_result";
|
||||
const OAUTH_RESULT_COOKIE = "connector_oauth_result";
|
||||
|
||||
function readOAuthResultCookie(): string | null {
|
||||
const match = document.cookie
|
||||
.split("; ")
|
||||
.find((row) => row.startsWith(`${OAUTH_RESULT_COOKIE}=`));
|
||||
return match ? decodeURIComponent(match.split("=").slice(1).join("=")) : null;
|
||||
}
|
||||
|
||||
function clearOAuthResultCookie(): void {
|
||||
// biome-ignore lint: only standard way to expire a cookie
|
||||
document.cookie = `${OAUTH_RESULT_COOKIE}=; path=/; max-age=0`;
|
||||
}
|
||||
|
||||
export const useConnectorDialog = () => {
|
||||
const searchSpaceId = useAtomValue(activeSearchSpaceIdAtom);
|
||||
|
|
@ -188,11 +200,11 @@ export const useConnectorDialog = () => {
|
|||
// Track whether the current indexing config came from an OAuth redirect
|
||||
const [isFromOAuth, setIsFromOAuth] = useState(false);
|
||||
|
||||
// Consume OAuth result from sessionStorage (set by /connectors/callback page)
|
||||
// Consume OAuth result from cookie (set by /connectors/callback route handler)
|
||||
useEffect(() => {
|
||||
const raw = sessionStorage.getItem(OAUTH_RESULT_KEY);
|
||||
const raw = readOAuthResultCookie();
|
||||
if (!raw || !searchSpaceId) return;
|
||||
sessionStorage.removeItem(OAUTH_RESULT_KEY);
|
||||
clearOAuthResultCookie();
|
||||
|
||||
let result: {
|
||||
success: string | null;
|
||||
|
|
@ -1188,6 +1200,9 @@ export const useConnectorDialog = () => {
|
|||
setConnectorName(null);
|
||||
setConnectorConfig(null);
|
||||
} else {
|
||||
setEditingConnector(null);
|
||||
setConnectorName(null);
|
||||
setConnectorConfig(null);
|
||||
setIsOpen(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue