mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-05 22:22:14 +00:00
fix: Disconnect GH -> Logout button (#138)
* fix: Disconnect GH -> Logout button * cr
This commit is contained in:
parent
4fbd1f4861
commit
a99a02223d
4 changed files with 17 additions and 11 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { GitHubSVG } from "@/components/icons/github";
|
import { GitHubSVG } from "@/components/icons/github";
|
||||||
|
import { LogOut } from "lucide-react";
|
||||||
|
import { TooltipIconButton } from "../ui/tooltip-icon-button";
|
||||||
|
|
||||||
export function GitHubOAuthButton() {
|
export function GitHubOAuthButton() {
|
||||||
const [isAuth, setIsAuth] = useState<boolean | null>(null);
|
const [isAuth, setIsAuth] = useState<boolean | null>(null);
|
||||||
|
|
@ -35,7 +37,9 @@ export function GitHubOAuthButton() {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
localStorage.removeItem("github_app_installed");
|
||||||
setIsAuth(false);
|
setIsAuth(false);
|
||||||
|
window.location.href = "/";
|
||||||
} else {
|
} else {
|
||||||
console.error("Logout failed");
|
console.error("Logout failed");
|
||||||
}
|
}
|
||||||
|
|
@ -65,16 +69,15 @@ export function GitHubOAuthButton() {
|
||||||
|
|
||||||
if (isAuth) {
|
if (isAuth) {
|
||||||
return (
|
return (
|
||||||
<Button
|
<TooltipIconButton
|
||||||
variant="outline"
|
tooltip="Logout"
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
className="text-xs"
|
className="text-xs"
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<GitHubSVG />
|
<LogOut className="size-4" />
|
||||||
{isLoading ? "Disconnecting..." : "Disconnect GitHub"}
|
</TooltipIconButton>
|
||||||
</Button>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ export function OpenPRButton() {
|
||||||
"text-gray-500 hover:text-gray-600": prState === "draft",
|
"text-gray-500 hover:text-gray-600": prState === "draft",
|
||||||
"text-[#8957e5] hover:text-[#7847d1]": prState === "merged",
|
"text-[#8957e5] hover:text-[#7847d1]": prState === "merged",
|
||||||
})}
|
})}
|
||||||
|
size="sm"
|
||||||
>
|
>
|
||||||
{prState === "merged" && <GitMerge className="size-4" />}
|
{prState === "merged" && <GitMerge className="size-4" />}
|
||||||
{prState === "draft" && <GitPullRequestDraft className="size-4" />}
|
{prState === "draft" && <GitPullRequestDraft className="size-4" />}
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,9 @@ export function getGitHubToken(request: NextRequest): GitHubTokenData | null {
|
||||||
* @param response NextResponse to set cookies on
|
* @param response NextResponse to set cookies on
|
||||||
*/
|
*/
|
||||||
export function clearGitHubToken(response: NextResponse): void {
|
export function clearGitHubToken(response: NextResponse): void {
|
||||||
const cookieOptions = getCookieOptions(new Date(0)); // Expire immediately
|
response.cookies.delete(GITHUB_TOKEN_COOKIE);
|
||||||
|
response.cookies.delete(GITHUB_TOKEN_TYPE_COOKIE);
|
||||||
response.cookies.set(GITHUB_TOKEN_COOKIE, "", cookieOptions);
|
response.cookies.delete(GITHUB_INSTALLATION_ID_COOKIE);
|
||||||
response.cookies.set(GITHUB_TOKEN_TYPE_COOKIE, "", cookieOptions);
|
|
||||||
response.cookies.set(GITHUB_INSTALLATION_ID_COOKIE, "", cookieOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -249,8 +249,12 @@ export async function getPullRequest(inputs: {
|
||||||
headBranch: string;
|
headBranch: string;
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
|
const queryParams = new URLSearchParams();
|
||||||
|
queryParams.set("base", inputs.baseBranch);
|
||||||
|
queryParams.set("head", inputs.headBranch);
|
||||||
|
queryParams.set("state", "all");
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${getBaseApiUrl()}github/proxy/repos/${inputs.owner}/${inputs.repo}/pulls?base=${inputs.baseBranch}&head=${inputs.headBranch}`,
|
`${getBaseApiUrl()}github/proxy/repos/${inputs.owner}/${inputs.repo}/pulls?${queryParams.toString()}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/vnd.github.v3+json",
|
Accept: "application/vnd.github.v3+json",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue