Skip to content
Closed
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
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ WEBSITE_URL=http://localhost:3001

# Neon MCP Server API key (for Claude Code integration)
NEON_API_KEY=your_neon_api_key_here
NEON_ORG_ID=org-round-base-25422821
NEON_PROJECT_ID=tiny-cherry-82420694

# Auth0 Authentication (Desktop App)
VITE_AUTH0_DOMAIN=your-tenant.auth0.com
VITE_AUTH0_CLIENT_ID=your_client_id_here
VITE_AUTH0_AUDIENCE=https://your-tenant.auth0.com/api/v2/

# Enable debug logging for auth (optional)
# DEBUG_AUTH=1
13 changes: 13 additions & 0 deletions apps/desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export default defineConfig({
main: {
plugins: [tsconfigPaths, copyResourcesPlugin()],

// Note: Auth0 credentials are loaded at runtime via dotenv in main/index.ts
// This allows environment-specific keys without rebuilding the app

define: {
"process.env.VITE_CLERK_PUBLISHABLE_KEY": JSON.stringify(
process.env.VITE_CLERK_PUBLISHABLE_KEY || "",
),
},

build: {
rollupOptions: {
input: {
Expand All @@ -66,6 +75,7 @@ export default defineConfig({
external: [
"electron",
"node-pty", // Native module - must stay external
"keytar", // Native module for secure credential storage
],
},
},
Expand Down Expand Up @@ -93,6 +103,9 @@ export default defineConfig({
},

renderer: {
// Load .env file for renderer (Vite exposes VITE_* vars via import.meta.env)
envDir: resolve(__dirname, "../.."),

define: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.platform": JSON.stringify(process.platform),
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"fast-glob": "^3.3.3",
"framer-motion": "^12.23.24",
"http-proxy": "^1.18.1",
"keytar": "^7.9.0",
"line-column-path": "^3.0.0",
"lodash": "^4.17.21",
"lowdb": "^7.0.1",
Expand Down
26 changes: 26 additions & 0 deletions apps/desktop/src/lib/trpc/routers/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { authManager } from "main/lib/auth";
import { publicProcedure, router } from "../..";

export const createAuthRouter = () => {
return router({
getSession: publicProcedure.query(async () => {
return await authManager.getSession();
}),

startSignIn: publicProcedure.mutation(async () => {
return await authManager.startSignIn();
}),

startSignUp: publicProcedure.mutation(async () => {
return await authManager.startSignUp();
}),

signOut: publicProcedure.mutation(async () => {
return await authManager.signOut();
}),

refreshSession: publicProcedure.mutation(async () => {
return await authManager.refreshSession();
}),
});
};
6 changes: 4 additions & 2 deletions apps/desktop/src/lib/trpc/routers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BrowserWindow } from "electron";
import { router } from "..";
import { createAuthRouter } from "./auth";
import { createChangesRouter } from "./changes";
import { createConfigRouter } from "./config";
import { createExternalRouter } from "./external";
Expand All @@ -22,17 +23,18 @@ import { createWorkspacesRouter } from "./workspaces";
*/
export const createAppRouter = (getWindow: () => BrowserWindow | null) => {
return router({
auth: createAuthRouter(),
changes: createChangesRouter(),
uiState: createUiStateRouter(),
window: createWindowRouter(getWindow),
projects: createProjectsRouter(getWindow),
workspaces: createWorkspacesRouter(),
terminal: createTerminalRouter(),
changes: createChangesRouter(),
notifications: createNotificationsRouter(),
menu: createMenuRouter(),
external: createExternalRouter(),
settings: createSettingsRouter(),
config: createConfigRouter(),
uiState: createUiStateRouter(),
ringtone: createRingtoneRouter(),
});
};
Expand Down
31 changes: 28 additions & 3 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// Load environment variables from .env file BEFORE any other imports
// This ensures Auth0 credentials are available at runtime (not compile-time)
// Use override: true to ensure .env values take precedence over inherited env vars
import path from "node:path";
import { config } from "dotenv";

config({
path: path.resolve(__dirname, "../../../../.env"),
override: true,
});

import { app } from "electron";
import { makeAppSetup } from "lib/electron-app/factories/app/setup";
import { setupAgentHooks } from "./lib/agent-setup";
import { initAppState } from "./lib/app-state";
import { authManager, registerAuthHandlers } from "./lib/auth";
import { setupAutoUpdater } from "./lib/auto-updater";
import { initDb } from "./lib/db";
import { terminalManager } from "./lib/terminal";
Expand All @@ -23,17 +34,30 @@ if (process.defaultApp) {
app.setAsDefaultProtocolClient(PROTOCOL_SCHEME);
}

// TODO: Handle deep link when app is already running
app.on("open-url", (event, _url) => {
// Handle deep links (including OAuth callbacks)
app.on("open-url", (event, url) => {
event.preventDefault();
console.log("[main] Received deep link:", url);

// Handle Auth0 OAuth callback
if (url.startsWith("superset://auth/callback")) {
authManager.handleCallback(url);
return;
}

// Other deep link handling can be added here
});

registerAuthHandlers();

// Allow multiple instances - removed single instance lock
(async () => {
await app.whenReady();

await initDb();
await initAppState();
// Validate auth session on startup
await authManager.validateSessionOnStartup();

try {
setupAgentHooks();
Expand All @@ -45,8 +69,9 @@ app.on("open-url", (event, _url) => {
await makeAppSetup(() => MainWindow());
setupAutoUpdater();

// Clean up all terminals when app is quitting
// Clean up when app is quitting
app.on("before-quit", async () => {
authManager.stopRefreshInterval();
await terminalManager.cleanup();
});
})();
27 changes: 27 additions & 0 deletions apps/desktop/src/main/lib/auth/auth-ipcs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ipcMain } from "electron";
import { authManager } from "./auth-manager";

/**
* Register IPC handlers for authentication
*/
export function registerAuthHandlers(): void {
ipcMain.handle("auth:get-session", async () => {
return await authManager.getSession();
});

ipcMain.handle("auth:start-sign-in", async () => {
return await authManager.startSignIn();
});

ipcMain.handle("auth:start-sign-up", async () => {
return await authManager.startSignUp();
});

ipcMain.handle("auth:sign-out", async () => {
return await authManager.signOut();
});

ipcMain.handle("auth:refresh-session", async () => {
return await authManager.refreshSession();
});
}
Loading