mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-05 14:12:11 +00:00
fix: Initial auth flow (#596)
This commit is contained in:
parent
137b600f58
commit
d098048fa7
6 changed files with 43 additions and 28 deletions
|
|
@ -148,12 +148,21 @@ export class ModelManager {
|
||||||
if (!apiKeys) {
|
if (!apiKeys) {
|
||||||
throw new Error("API keys not found in config");
|
throw new Error("API keys not found in config");
|
||||||
}
|
}
|
||||||
apiKey = decryptSecret(
|
const providerApiKey = providerToApiKey(provider, apiKeys);
|
||||||
providerToApiKey(provider, apiKeys),
|
if (!providerApiKey) {
|
||||||
secretsEncryptionKey,
|
throw new Error(
|
||||||
);
|
"No API key found for provider: " +
|
||||||
|
provider +
|
||||||
|
". Please add one in the settings page.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
apiKey = decryptSecret(providerApiKey, secretsEncryptionKey);
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error("No API key found for provider: " + provider);
|
throw new Error(
|
||||||
|
"No API key found for provider: " +
|
||||||
|
provider +
|
||||||
|
". Please add one in the settings page.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,10 @@ import { LangGraphLogoSVG } from "../icons/langgraph";
|
||||||
import { useGitHubToken } from "@/hooks/useGitHubToken";
|
import { useGitHubToken } from "@/hooks/useGitHubToken";
|
||||||
import { useGitHubAppProvider } from "@/providers/GitHubApp";
|
import { useGitHubAppProvider } from "@/providers/GitHubApp";
|
||||||
import { GitHubAppProvider } from "@/providers/GitHubApp";
|
import { GitHubAppProvider } from "@/providers/GitHubApp";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
function AuthStatusContent() {
|
function AuthStatusContent() {
|
||||||
|
const router = useRouter();
|
||||||
const [isAuth, setIsAuth] = useState<boolean | null>(null);
|
const [isAuth, setIsAuth] = useState<boolean | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
|
@ -61,7 +63,18 @@ function AuthStatusContent() {
|
||||||
window.location.href = "/api/github/installation";
|
window.location.href = "/api/github/installation";
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isAuth) {
|
const showGetStarted = !isAuth;
|
||||||
|
const showInstallApp =
|
||||||
|
!showGetStarted && !hasGitHubAppInstalled && !isTokenLoading;
|
||||||
|
const showLoading = !showGetStarted && !showInstallApp && !githubToken;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showGetStarted && !showInstallApp && !showLoading) {
|
||||||
|
router.push("/chat");
|
||||||
|
}
|
||||||
|
}, [showGetStarted, showInstallApp, showLoading]);
|
||||||
|
|
||||||
|
if (showGetStarted) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
||||||
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
||||||
|
|
@ -91,7 +104,7 @@ function AuthStatusContent() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAuth && hasGitHubAppInstalled === false && !isTokenLoading) {
|
if (showInstallApp) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
||||||
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
||||||
|
|
@ -124,7 +137,7 @@ function AuthStatusContent() {
|
||||||
<Button
|
<Button
|
||||||
onClick={handleInstallGitHubApp}
|
onClick={handleInstallGitHubApp}
|
||||||
disabled={isLoading || isCheckingAppInstallation}
|
disabled={isLoading || isCheckingAppInstallation}
|
||||||
className="bg-black hover:bg-gray-800"
|
className="bg-black hover:bg-gray-800 dark:bg-white dark:hover:bg-gray-200"
|
||||||
>
|
>
|
||||||
<GitHubSVG
|
<GitHubSVG
|
||||||
width="16"
|
width="16"
|
||||||
|
|
@ -140,7 +153,7 @@ function AuthStatusContent() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!githubToken) {
|
if (showLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
<div className="flex min-h-screen w-full items-center justify-center p-4">
|
||||||
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
<div className="animate-in fade-in-0 zoom-in-95 flex w-full max-w-3xl flex-col rounded-lg border shadow-lg">
|
||||||
|
|
|
||||||
|
|
@ -653,13 +653,6 @@ export function AssistantMessage({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionableToolCalls.length > 0) {
|
if (actionableToolCalls.length > 0) {
|
||||||
if (
|
|
||||||
actionableToolCalls[0].name !== "shell" &&
|
|
||||||
actionableToolCalls[0].name !== "scratchpad" &&
|
|
||||||
actionableToolCalls[0].name !== "grep"
|
|
||||||
) {
|
|
||||||
console.log("actionableToolCalls", actionableToolCalls[0]);
|
|
||||||
}
|
|
||||||
const actionItems = actionableToolCalls.map((toolCall): ActionItemProps => {
|
const actionItems = actionableToolCalls.map((toolCall): ActionItemProps => {
|
||||||
const correspondingToolResult = toolResults.find(
|
const correspondingToolResult = toolResults.find(
|
||||||
(tr) => tr && tr.tool_call_id === toolCall.id,
|
(tr) => tr && tr.tool_call_id === toolCall.id,
|
||||||
|
|
|
||||||
|
|
@ -204,12 +204,6 @@ export function APIKeysTab() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<p className="text-muted-foreground text-xs">
|
|
||||||
Your API key is stored
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -230,8 +230,8 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
setError("Failed to check GitHub App installation status");
|
setError("Failed to check GitHub App installation status");
|
||||||
setIsInstalled(false);
|
setIsInstalled(false);
|
||||||
} finally {
|
} finally {
|
||||||
if (!append) setIsLoading(false);
|
setIsLoading(false);
|
||||||
if (append) setRepositoriesLoadingMore(false);
|
setRepositoriesLoadingMore(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -352,9 +352,9 @@ export function useGitHubApp(): UseGitHubAppReturn {
|
||||||
}
|
}
|
||||||
|
|
||||||
previousInstallationIdRef.current = currentInstallationId;
|
previousInstallationIdRef.current = currentInstallationId;
|
||||||
|
|
||||||
checkInstallation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkInstallation();
|
||||||
}, [currentInstallationId]);
|
}, [currentInstallationId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { GITHUB_TOKEN_COOKIE } from "@open-swe/shared/constants";
|
import {
|
||||||
|
GITHUB_TOKEN_COOKIE,
|
||||||
|
GITHUB_INSTALLATION_ID_COOKIE,
|
||||||
|
} from "@open-swe/shared/constants";
|
||||||
import { verifyGithubUser } from "@open-swe/shared/github/verify-user";
|
import { verifyGithubUser } from "@open-swe/shared/github/verify-user";
|
||||||
|
|
||||||
export async function middleware(request: NextRequest) {
|
export async function middleware(request: NextRequest) {
|
||||||
const token = request.cookies.get(GITHUB_TOKEN_COOKIE)?.value;
|
const token = request.cookies.get(GITHUB_TOKEN_COOKIE)?.value;
|
||||||
const user = token ? await verifyGithubUser(token) : null;
|
const installationId = request.cookies.get(
|
||||||
|
GITHUB_INSTALLATION_ID_COOKIE,
|
||||||
|
)?.value;
|
||||||
|
const user = token && installationId ? await verifyGithubUser(token) : null;
|
||||||
|
|
||||||
if (request.nextUrl.pathname === "/") {
|
if (request.nextUrl.pathname === "/") {
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue