Skip to content
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

feat: get meta only when login #127

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions frontend/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { GitHubMeta, JWTPayload } from "./types";
import { apiEndpoint } from "./const";

export let githubMeta: GitHubMeta;

export const fetchGitHubMeta = async () => {
export const fetchGitHubMeta = async (): Promise<GitHubMeta> => {
const res = await fetch(`${apiEndpoint}meta/github-app`, {
method: "GET",
});
Expand All @@ -12,7 +10,7 @@ export const fetchGitHubMeta = async () => {
throw res;
}

if (!githubMeta) githubMeta = (await res.json()).data;
return (await res.json()).data;
};

export const handleOAuthToken = () => {
Expand Down
7 changes: 2 additions & 5 deletions frontend/lib/dom/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import iconEdit from "iconify/edit";
import iconDelete from "iconify/delete";
import iconInfoOutlineRounded from "iconify/info-outline-rounded";
import { Comment } from "../types";
import { getJWT, decodeJWT, logout, githubMeta } from "../auth";
import { getJWT, decodeJWT, logout, fetchGitHubMeta } from "../auth";
import { apiEndpoint } from "../const";
import { groupBy, dateTimeFormatter } from "../util";

Expand Down Expand Up @@ -691,10 +691,7 @@ export const renderComments = async (comments: Comment[]) => {
break;
}
case "login": {
if (!githubMeta) {
console.log("githubMeta not ready");
return;
}
const githubMeta = await fetchGitHubMeta();
window.location.href = `https://github.com/login/oauth/authorize?client_id=${githubMeta.client_id}&state=${encodeURIComponent(JSON.stringify({ redirect: window.location.href }))}`;
break;
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./style.css";
import iconComment from "iconify/comment-outline-rounded";
import iconClose from "iconify/close";
import { setApiEndpoint } from "./const";
import { fetchGitHubMeta, handleOAuthToken } from "./auth";
import { handleOAuthToken } from "./auth";
import {
closeContextMenu,
createContextMenu,
Expand Down Expand Up @@ -71,7 +71,6 @@ export function setupReview(
resetCommentsCache();

updateAvailableComments();
fetchGitHubMeta();

if (globalInitialized) {
closeCommentsPanel();
Expand Down