feat(supabase): add credentials handling for Supabase API keys and URL
This commit introduces the ability to fetch and store Supabase API keys and URL credentials when a project is selected. This enables the application to dynamically configure the Supabase connection environment variables, improving the integration with Supabase services. The changes include updates to the Supabase connection logic, new API endpoints, and modifications to the chat and prompt components to utilize the new credentials.
This commit is contained in:
@@ -45,6 +45,10 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
|
||||
supabase?: {
|
||||
isConnected: boolean;
|
||||
hasSelectedProject: boolean;
|
||||
credentials?: {
|
||||
anonKey?: string;
|
||||
supabaseUrl?: string;
|
||||
};
|
||||
};
|
||||
}>();
|
||||
|
||||
@@ -183,7 +187,6 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
|
||||
// logger.debug('Code Files Selected');
|
||||
}
|
||||
|
||||
// Stream the text
|
||||
const options: StreamingOptions = {
|
||||
supabaseConnection: supabase,
|
||||
toolChoice: 'none',
|
||||
|
||||
@@ -7,7 +7,6 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
return json({ error: 'Method not allowed' }, { status: 405 });
|
||||
}
|
||||
|
||||
// Inside the action function
|
||||
try {
|
||||
const { token } = (await request.json()) as any;
|
||||
|
||||
@@ -27,17 +26,14 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
|
||||
const projects = (await projectsResponse.json()) as SupabaseProject[];
|
||||
|
||||
// Create a Map to store unique projects by ID
|
||||
const uniqueProjectsMap = new Map<string, SupabaseProject>();
|
||||
|
||||
// Only keep the latest version of each project
|
||||
for (const project of projects) {
|
||||
if (!uniqueProjectsMap.has(project.id)) {
|
||||
uniqueProjectsMap.set(project.id, project);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug log to see unique projects
|
||||
console.log(
|
||||
'Unique projects:',
|
||||
Array.from(uniqueProjectsMap.values()).map((p) => ({ id: p.id, name: p.name })),
|
||||
@@ -45,7 +41,6 @@ export const action: ActionFunction = async ({ request }) => {
|
||||
|
||||
const uniqueProjects = Array.from(uniqueProjectsMap.values());
|
||||
|
||||
// Sort projects by creation date (newest first)
|
||||
uniqueProjects.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
|
||||
return json({
|
||||
|
||||
33
app/routes/api.supabase.variables.ts
Normal file
33
app/routes/api.supabase.variables.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { json } from '@remix-run/node';
|
||||
import type { ActionFunctionArgs } from '@remix-run/node';
|
||||
|
||||
export async function action({ request }: ActionFunctionArgs) {
|
||||
try {
|
||||
// Add proper type assertion for the request body
|
||||
const body = (await request.json()) as { projectId?: string; token?: string };
|
||||
const { projectId, token } = body;
|
||||
|
||||
if (!projectId || !token) {
|
||||
return json({ error: 'Project ID and token are required' }, { status: 400 });
|
||||
}
|
||||
|
||||
const response = await fetch(`https://api.supabase.com/v1/projects/${projectId}/api-keys`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return json({ error: `Failed to fetch API keys: ${response.statusText}` }, { status: response.status });
|
||||
}
|
||||
|
||||
const apiKeys = await response.json();
|
||||
|
||||
return json({ apiKeys });
|
||||
} catch (error) {
|
||||
console.error('Error fetching project API keys:', error);
|
||||
return json({ error: error instanceof Error ? error.message : 'Unknown error occurred' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user