Basic Supabase OAuth integration & project-app binding
This commit is contained in:
@@ -37,6 +37,7 @@ import { getGitAuthor } from "../utils/git_author";
|
||||
import killPort from "kill-port";
|
||||
import util from "util";
|
||||
import log from "electron-log";
|
||||
import { getSupabaseProjectName } from "../utils/supabase_management_client";
|
||||
|
||||
const logger = log.scope("app_handlers");
|
||||
|
||||
@@ -222,9 +223,16 @@ export function registerAppHandlers() {
|
||||
// Return app even if files couldn't be read
|
||||
}
|
||||
|
||||
let supabaseProjectName: string | null = null;
|
||||
|
||||
if (app.supabaseProjectId) {
|
||||
supabaseProjectName = await getSupabaseProjectName(app.supabaseProjectId);
|
||||
}
|
||||
|
||||
return {
|
||||
...app,
|
||||
files,
|
||||
supabaseProjectName,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
65
src/ipc/handlers/supabase_handlers.ts
Normal file
65
src/ipc/handlers/supabase_handlers.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { ipcMain } from "electron";
|
||||
import { SupabaseManagementAPI } from "supabase-management-js";
|
||||
import { readSettings, writeSettings } from "../../main/settings";
|
||||
import log from "electron-log";
|
||||
import { db } from "../../db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { apps } from "../../db/schema";
|
||||
import { getSupabaseClient } from "../utils/supabase_management_client";
|
||||
|
||||
const logger = log.scope("supabase_handlers");
|
||||
|
||||
export function registerSupabaseHandlers() {
|
||||
// List all Supabase projects
|
||||
ipcMain.handle("supabase:list-projects", async () => {
|
||||
try {
|
||||
const supabase = await getSupabaseClient();
|
||||
// Call the API according to supabase-management-js structure
|
||||
const projects = await supabase.getProjects();
|
||||
return projects;
|
||||
} catch (error) {
|
||||
logger.error("Error listing Supabase projects:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// Set app project - links a Dyad app to a Supabase project
|
||||
ipcMain.handle(
|
||||
"supabase:set-app-project",
|
||||
async (_, { project, app }: { project: string; app: number }) => {
|
||||
try {
|
||||
// Here you could store the project-app association in your database
|
||||
// For example:
|
||||
await db
|
||||
.update(apps)
|
||||
.set({ supabaseProjectId: project })
|
||||
.where(eq(apps.id, app));
|
||||
|
||||
logger.info(`Associated app ${app} with Supabase project ${project}`);
|
||||
return { success: true, appId: app, projectId: project };
|
||||
} catch (error) {
|
||||
logger.error("Error setting Supabase project for app:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Unset app project - removes the link between a Dyad app and a Supabase project
|
||||
ipcMain.handle(
|
||||
"supabase:unset-app-project",
|
||||
async (_, { app }: { app: number }) => {
|
||||
try {
|
||||
await db
|
||||
.update(apps)
|
||||
.set({ supabaseProjectId: null })
|
||||
.where(eq(apps.id, app));
|
||||
|
||||
logger.info(`Removed Supabase project association for app ${app}`);
|
||||
return { success: true, appId: app };
|
||||
} catch (error) {
|
||||
logger.error("Error unsetting Supabase project for app:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -676,6 +676,51 @@ export class IpcClient {
|
||||
}
|
||||
// --- End Proposal Management ---
|
||||
|
||||
// --- Supabase Management ---
|
||||
public async listSupabaseProjects(): Promise<any[]> {
|
||||
try {
|
||||
const projects = await this.ipcRenderer.invoke("supabase:list-projects");
|
||||
return projects;
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async setSupabaseAppProject(
|
||||
project: string,
|
||||
app: number
|
||||
): Promise<{ success: boolean; appId: number; projectId: string }> {
|
||||
try {
|
||||
const result = await this.ipcRenderer.invoke("supabase:set-app-project", {
|
||||
project,
|
||||
app,
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async unsetSupabaseAppProject(
|
||||
app: number
|
||||
): Promise<{ success: boolean; appId: number }> {
|
||||
try {
|
||||
const result = await this.ipcRenderer.invoke(
|
||||
"supabase:unset-app-project",
|
||||
{
|
||||
app,
|
||||
}
|
||||
);
|
||||
return result;
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// --- End Supabase Management ---
|
||||
|
||||
// Get system debug information
|
||||
public async getSystemDebugInfo(): Promise<SystemDebugInfo> {
|
||||
try {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { registerGithubHandlers } from "./handlers/github_handlers";
|
||||
import { registerNodeHandlers } from "./handlers/node_handlers";
|
||||
import { registerProposalHandlers } from "./handlers/proposal_handlers";
|
||||
import { registerDebugHandlers } from "./handlers/debug_handlers";
|
||||
import { registerSupabaseHandlers } from "./handlers/supabase_handlers";
|
||||
|
||||
export function registerIpcHandlers() {
|
||||
// Register all IPC handlers by category
|
||||
@@ -21,4 +22,5 @@ export function registerIpcHandlers() {
|
||||
registerNodeHandlers();
|
||||
registerProposalHandlers();
|
||||
registerDebugHandlers();
|
||||
registerSupabaseHandlers();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ export interface App {
|
||||
updatedAt: Date;
|
||||
githubOrg: string | null;
|
||||
githubRepo: string | null;
|
||||
supabaseProjectId: string | null;
|
||||
supabaseProjectName: string | null;
|
||||
}
|
||||
|
||||
export interface Version {
|
||||
|
||||
28
src/ipc/utils/supabase_management_client.ts
Normal file
28
src/ipc/utils/supabase_management_client.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { readSettings } from "../../main/settings";
|
||||
import { SupabaseManagementAPI } from "supabase-management-js";
|
||||
|
||||
// Function to get the Supabase Management API client
|
||||
export async function getSupabaseClient(): Promise<SupabaseManagementAPI> {
|
||||
const settings = readSettings();
|
||||
// Check if Supabase token exists in settings
|
||||
const supabaseAccessToken = settings.supabase?.accessToken?.value;
|
||||
|
||||
if (!supabaseAccessToken) {
|
||||
throw new Error(
|
||||
"Supabase access token not found. Please authenticate first."
|
||||
);
|
||||
}
|
||||
|
||||
return new SupabaseManagementAPI({
|
||||
accessToken: supabaseAccessToken,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSupabaseProjectName(
|
||||
projectId: string
|
||||
): Promise<string> {
|
||||
const supabase = await getSupabaseClient();
|
||||
const projects = await supabase.getProjects();
|
||||
const project = projects?.find((p) => p.id === projectId);
|
||||
return project?.name || `<project not found for: ${projectId}>`;
|
||||
}
|
||||
Reference in New Issue
Block a user