Skip to content

refactor: poll for git auth updates when creating a workspace #9804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 26, 2023
Prev Previous commit
Next Next commit
remove BroadcastChannel stuff
  • Loading branch information
aslilac committed Sep 22, 2023
commit e4d67b9b67b9e9d4114aad9bb9a3e45a02abd4b4
11 changes: 0 additions & 11 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ const renderCreateWorkspacePage = () => {
});
};

Object.defineProperty(window, "BroadcastChannel", {
value: class {
addEventListener() {
// noop
}
close() {
// noop
}
},
});

describe("CreateWorkspacePage", () => {
it("succeeds with default owner", async () => {
jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,8 @@ type GitAuthErrors = Record<string, string>;
const useGitAuthVerification = (gitAuth: TypesGen.TemplateVersionGitAuth[]) => {
const [gitAuthErrors, setGitAuthErrors] = useState<GitAuthErrors>({});

// Clear errors when gitAuth is refreshed
useEffect(() => {
// templateGitAuth is refreshed automatically using a BroadcastChannel
// which may change the `authenticated` property.
//
// If the provider becomes authenticated, we want the error message
// to disappear.
setGitAuthErrors({});
}, [gitAuth]);

Expand Down
14 changes: 1 addition & 13 deletions site/src/pages/GitAuthPage/GitAuthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
getGitAuthProvider,
} from "api/api";
import { usePermissions } from "hooks";
import { FC, useEffect } from "react";
import { type FC } from "react";
import { useParams } from "react-router-dom";
import GitAuthPageView from "./GitAuthPageView";
import { ApiErrorResponse } from "api/errors";
import { isAxiosError } from "axios";
import { REFRESH_GITAUTH_BROADCAST_CHANNEL } from "utils/gitAuth";

const GitAuthPage: FC = () => {
const { provider } = useParams();
Expand Down Expand Up @@ -52,17 +51,6 @@ const GitAuthPage: FC = () => {
query.state.status === "success" ? false : "always",
});

useEffect(() => {
if (!getGitAuthProviderQuery.data?.authenticated) {
return;
}
// This is used to notify the parent window that the Git auth token has been refreshed.
// It's critical in the create workspace flow!
const bc = new BroadcastChannel(REFRESH_GITAUTH_BROADCAST_CHANNEL);
// The message doesn't matter, any message refreshes the page!
bc.postMessage("noop");
}, [getGitAuthProviderQuery.data?.authenticated]);

if (getGitAuthProviderQuery.isLoading || !getGitAuthProviderQuery.data) {
return null;
}
Expand Down
12 changes: 0 additions & 12 deletions site/src/pages/GitAuthPage/GitAuthPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ const GitAuthPageView: FC<GitAuthPageViewProps> = ({
}) => {
const styles = useStyles();

useEffect(() => {
if (!gitAuth.authenticated) {
return;
}
// This is used to notify the parent window that the Git auth token has been refreshed.
// It's critical in the create workspace flow!
// eslint-disable-next-line compat/compat -- It actually is supported... not sure why it's complaining.
const bc = new BroadcastChannel(REFRESH_GITAUTH_BROADCAST_CHANNEL);
// The message doesn't matter, any message refreshes the page!
bc.postMessage("noop");
}, [gitAuth.authenticated]);

if (!gitAuth.authenticated) {
return (
<SignInLayout>
Expand Down