Skip to content

Commit 8a7b157

Browse files
authored
feat(GitHub Integration): Keep GitHub auth cookie within the same session if the data source doesn't change (#535)
1 parent ed75b81 commit 8a7b157

File tree

1 file changed

+8
-1
lines changed
  • src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph/components/SceneFunctionDetailsPanel/components/GitHubContextProvider

1 file changed

+8
-1
lines changed

src/pages/ProfilesExplorerView/components/SceneExploreServiceFlameGraph/components/SceneFunctionDetailsPanel/components/GitHubContextProvider/GitHubContextProvider.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type GitHubContextProviderProps = {
1717

1818
export const nonce = generateNonce();
1919

20+
// Keep the data source UID in session storage to reuse it if the page is refreshed
21+
const SESSION_DATA_SOURCE_KEY = `grafana-pyroscope-app.gitHubIntegration.dataSourceUid`;
22+
2023
export function GitHubContextProvider({ dataSourceUid, children }: GitHubContextProviderProps) {
2124
const vcsClient = DataSourceProxyClientBuilder.build(dataSourceUid, VcsClient);
2225
const privateVcsClient = DataSourceProxyClientBuilder.build(dataSourceUid, PrivateVcsClient);
@@ -29,7 +32,11 @@ export function GitHubContextProvider({ dataSourceUid, children }: GitHubContext
2932
// when logged in and changing data source
3033
// TODO: provide a better way
3134
useEffect(() => {
32-
setSessionCookie('');
35+
const gitHubIntegrationDataSourceUid = sessionStorage.getItem(SESSION_DATA_SOURCE_KEY);
36+
if (gitHubIntegrationDataSourceUid !== dataSourceUid) {
37+
setSessionCookie('');
38+
sessionStorage.setItem(SESSION_DATA_SOURCE_KEY, dataSourceUid || '');
39+
}
3340
}, [dataSourceUid]); // eslint-disable-line react-hooks/exhaustive-deps
3441

3542
usePollGitHubPopup({ vcsClient, externalWindow, setExternalWindow, setSessionCookie, nonce });

0 commit comments

Comments
 (0)