From 4d362f320c88b7411798a7e273f82f79a384e534 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 2 Mar 2026 20:03:18 -0500 Subject: [PATCH] Auto-restart after GitHub App setup instead of requiring manual restart Set env vars on process.env at runtime after writing .env, then redirect to /auth/login. Removes the success UI telling users to restart. Co-Authored-By: Claude Opus 4.6 --- apps/arc-web/app/routes/setup-callback.tsx | 61 ++++++++++++---------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/apps/arc-web/app/routes/setup-callback.tsx b/apps/arc-web/app/routes/setup-callback.tsx index eefee362f..82081e036 100644 --- a/apps/arc-web/app/routes/setup-callback.tsx +++ b/apps/arc-web/app/routes/setup-callback.tsx @@ -1,6 +1,7 @@ import { readFile, writeFile } from "node:fs/promises"; import { resolve } from "node:path"; import { randomBytes } from "node:crypto"; +import { redirect } from "react-router"; import type { Route } from "./+types/setup-callback"; const ENV_PATH = resolve(import.meta.dirname, "../../../../.env"); @@ -9,7 +10,7 @@ export async function loader({ request }: Route.LoaderArgs) { const url = new URL(request.url); const code = url.searchParams.get("code"); if (!code) { - return { success: false, error: "Missing code parameter" }; + return { error: "Missing code parameter" }; } const response = await fetch( @@ -19,10 +20,7 @@ export async function loader({ request }: Route.LoaderArgs) { if (!response.ok) { const body = await response.text(); - return { - success: false, - error: `GitHub API error: ${response.status} ${body}`, - }; + return { error: `GitHub API error: ${response.status} ${body}` }; } const data = (await response.json()) as { @@ -54,33 +52,42 @@ export async function loader({ request }: Route.LoaderArgs) { const envContent = existing ? `${existing.trimEnd()}\n\n${newVars}\n` : `${newVars}\n`; await writeFile(ENV_PATH, envContent, "utf-8"); - return { success: true, error: null }; + process.env.SESSION_SECRET = sessionSecret; + process.env.GITHUB_APP_ID = String(data.id); + process.env.GITHUB_APP_CLIENT_ID = data.client_id; + process.env.GITHUB_APP_CLIENT_SECRET = data.client_secret; + process.env.GITHUB_APP_WEBHOOK_SECRET = data.webhook_secret; + process.env.GITHUB_APP_PRIVATE_KEY = data.pem; + + throw redirect("/auth/login"); } export default function SetupCallback({ loaderData }: Route.ComponentProps) { - const { success, error } = loaderData; + const { error } = loaderData; return ( -
-
- {success ? ( - <> -

- GitHub App registered -

-

- Credentials have been written to .env. Restart the - app to pick up the new configuration. -

- - ) : ( - <> -

- Setup failed -

-

{error}

- - )} +
+
+
+ Arc +
+
+
+ + + +
+

+ Setup failed +

+

{error}

+ + Try again + +
);