fix: Initial auth flow (#596)

This commit is contained in:
Brace Sproul 2025-07-29 14:24:22 -07:00 • committed by GitHub
parent 137b600f58
commit d098048fa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 28 deletions

View file

@ -148,12 +148,21 @@ export class ModelManager {
if (!apiKeys) {
throw new Error("API keys not found in config");
}
apiKey = decryptSecret(
providerToApiKey(provider, apiKeys),
secretsEncryptionKey,
);
const providerApiKey = providerToApiKey(provider, apiKeys);
if (!providerApiKey) {
throw new Error(
"No API key found for provider: " +
provider +
". Please add one in the settings page.",
);
}
apiKey = decryptSecret(providerApiKey, secretsEncryptionKey);
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.",
);
}
}
}

View file

@ -7,8 +7,10 @@ import { LangGraphLogoSVG } from "../icons/langgraph";
import { useGitHubToken } from "@/hooks/useGitHubToken";
import { useGitHubAppProvider } from "@/providers/GitHubApp";
import { GitHubAppProvider } from "@/providers/GitHubApp";
import { useRouter } from "next/navigation";
function AuthStatusContent() {
const router = useRouter();
const [isAuth, setIsAuth] = useState<boolean | null>(null);
const [isLoading, setIsLoading] = useState(false);
@ -61,7 +63,18 @@ function AuthStatusContent() {
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 (
<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">
@ -91,7 +104,7 @@ function AuthStatusContent() {
);
}
if (isAuth && hasGitHubAppInstalled === false && !isTokenLoading) {
if (showInstallApp) {
return (
<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">
@ -124,7 +137,7 @@ function AuthStatusContent() {
<Button
onClick={handleInstallGitHubApp}
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
width="16"
@ -140,7 +153,7 @@ function AuthStatusContent() {
);
}
if (!githubToken) {
if (showLoading) {
return (
<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">

View file

@ -653,13 +653,6 @@ export function AssistantMessage({
}
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 correspondingToolResult = toolResults.find(
(tr) => tr && tr.tool_call_id === toolCall.id,

View file

@ -204,12 +204,6 @@ export function APIKeysTab() {
</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>
))}

View file

@ -230,8 +230,8 @@ export function useGitHubApp(): UseGitHubAppReturn {
setError("Failed to check GitHub App installation status");
setIsInstalled(false);
} finally {
if (!append) setIsLoading(false);
if (append) setRepositoriesLoadingMore(false);
setIsLoading(false);
setRepositoriesLoadingMore(false);
}
};
@ -352,9 +352,9 @@ export function useGitHubApp(): UseGitHubAppReturn {
}
previousInstallationIdRef.current = currentInstallationId;
checkInstallation();
}
checkInstallation();
}, [currentInstallationId]);
useEffect(() => {

View file

@ -1,10 +1,16 @@
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";
export async function middleware(request: NextRequest) {
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 (user) {