-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathsetup.ts
More file actions
86 lines (74 loc) · 2.02 KB
/
Copy pathsetup.ts
File metadata and controls
86 lines (74 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Setup API Client
*
* Handles communication with Next.js setup API routes
*/
import type { ApiResponse, SupabaseConfig } from '@/types';
/**
* Check if setup is complete
*/
export async function checkSetupStatus(): Promise<{
is_configured: boolean;
is_setup_complete: boolean;
is_vercel: boolean;
error?: string;
}> {
const response = await fetch('/ycode/api/setup/status');
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return response.json();
}
/**
* Connect Supabase credentials (4 fields)
*/
export async function connectSupabase(
config: SupabaseConfig
): Promise<ApiResponse<void>> {
const response = await fetch('/ycode/api/setup/connect', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
anon_key: config.anonKey,
service_role_key: config.serviceRoleKey,
connection_url: config.connectionUrl,
db_password: config.dbPassword,
...(config.supabaseUrl ? { supabase_url: config.supabaseUrl } : {}),
}),
});
return response.json();
}
/**
* Run Supabase migrations (checks and runs if needed)
*/
export async function runMigrations(): Promise<ApiResponse<void>> {
const response = await fetch('/ycode/api/setup/migrate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
return response.json();
}
/**
* Check if Supabase "Confirm email" setting is disabled (autoconfirm enabled)
*/
export async function checkEmailConfirmDisabled(): Promise<{
autoconfirm: boolean;
error?: string;
}> {
const response = await fetch('/ycode/api/setup/check-email-confirm');
const data = await response.json();
if (!response.ok) {
throw new Error(data?.error || `HTTP ${response.status}: ${response.statusText}`);
}
return data;
}
/**
* Complete setup (no-op now, kept for compatibility)
*/
export async function completeSetup(): Promise<ApiResponse<{ redirect_url: string }>> {
return {
data: {
redirect_url: '/ycode',
},
};
}