Skip to content

Commit

Permalink
feat: remove org member code
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Dec 4, 2024
1 parent 96a8ef5 commit fde134f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
24 changes: 0 additions & 24 deletions src/home/getters/get-github-access-token.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
declare const SUPABASE_STORAGE_KEY: string; // @DEV: passed in at build time check build/esbuild-build.ts
import { Octokit } from "@octokit/rest";
import { checkSupabaseSession } from "../rendering/render-github-login-button";
import { getLocalStore } from "./get-local-store";

/**
* Checks if the logged-in user is part of Ubiquity's Org, and didn't grant the 'repo' scope
*/
export async function isOrgMemberWithoutScope() {
const octokit = new Octokit({ auth: await getGitHubAccessToken() });
try {
await octokit.orgs.getMembershipForAuthenticatedUser({
org: "ubiquity",
});
} catch (e) {
if (e && typeof e === "object" && "status" in e && e.status === 404) {
return false;
}
throw e;
}
const { headers } = await octokit.request("HEAD /");
if (headers) {
const scopes = headers["x-oauth-scopes"]?.split(", ");
return !scopes?.includes("repo");
}
return false;
}

export async function getGitHubAccessToken(): Promise<string | null> {
// better to use official function, looking up localstorage has flaws
const oauthToken = await checkSupabaseSession();
Expand Down
9 changes: 1 addition & 8 deletions src/home/rendering/display-github-user-information.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { isOrgMemberWithoutScope } from "../getters/get-github-access-token";
import { GitHubUser } from "../github-types";
import { toolbar } from "../ready-toolbar";
import { renderErrorInModal } from "./display-popup-modal";
import { authenticationElement, getSupabase, renderAugmentAccessButton } from "./render-github-login-button";
import { authenticationElement, getSupabase } from "./render-github-login-button";

export async function displayGitHubUserInformation(gitHubUser: GitHubUser) {
const authenticatedDivElement = document.createElement("div");
const containerDivElement = document.createElement("div");
authenticatedDivElement.id = "authenticated";
authenticatedDivElement.classList.add("user-container");
if (!toolbar) throw new Error("toolbar not found");
Expand Down Expand Up @@ -37,11 +35,6 @@ export async function displayGitHubUserInformation(gitHubUser: GitHubUser) {
window.location.replace("/");
});

if (await isOrgMemberWithoutScope()) {
const accessButton = renderAugmentAccessButton();
containerDivElement.appendChild(accessButton);
}

authenticationElement.appendChild(authenticatedDivElement);
toolbar.setAttribute("data-authenticated", "true");
toolbar.classList.add("ready");
Expand Down

0 comments on commit fde134f

Please sign in to comment.