in app/lib/authService.ts [78:120]
static async authenticate(credentials: {
openaiApiKey?: string;
huggingfaceToken?: string;
}): Promise<{ success: boolean; error?: string; hfUserInfo?: HFUserInfo }> {
try {
// Validate credentials format on client side first
if (!this.validateCredentials(credentials)) {
return { success: false, error: "Invalid credentials format" };
}
const response = await fetch(this.API_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include", // Include cookies in request
body: JSON.stringify({
action: "authenticate",
credentials,
}),
});
const result = await response.json();
if (!response.ok) {
return {
success: false,
error: result.error || `Authentication failed: ${response.status}`,
};
}
return {
success: true,
hfUserInfo: result.hfUserInfo,
};
} catch (error) {
console.error("Authentication request failed:", error);
return {
success: false,
error: "Network error during authentication",
};
}
}