diff --git a/surfsense_web/lib/apis/auth.api.ts b/surfsense_web/lib/apis/auth.api.ts new file mode 100644 index 000000000..94865fcdb --- /dev/null +++ b/surfsense_web/lib/apis/auth.api.ts @@ -0,0 +1,55 @@ +export const login = async (request: { + username: string; + password: string; + grant_type?: string; +}) => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/auth/jwt/login`, + { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: JSON.stringify({ + username: request.username, + password: request.password, + grant_type: request.grant_type || "password", + }), + } + ); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.detail || `HTTP ${response.status}`); + } + + return data; +}; + +export const register = async (request: { + email: string; + password: string; + is_active: boolean; + is_superuser: boolean; + is_verified: boolean; +}) => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/auth/register`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(request), + } + ); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.detail || `HTTP ${response.status}`); + } + + return data; +}; diff --git a/surfsense_web/lib/apis/search-spaces.api.ts b/surfsense_web/lib/apis/search-spaces.api.ts index 89a437e9f..2ded72f44 100644 --- a/surfsense_web/lib/apis/search-spaces.api.ts +++ b/surfsense_web/lib/apis/search-spaces.api.ts @@ -89,3 +89,24 @@ export const fetchSearchSpace = async (searchSpaceId: string) => { return await response.json(); }; + +export const fetchSearchSpacePreferences = async ( + searchSpaceId: number, + authToken: string +) => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-spaces/${searchSpaceId}/llm-preferences`, + { + headers: { + Authorization: `Bearer ${authToken}`, + }, + method: "GET", + } + ); + + if (!response.ok) { + throw new Error("Failed to fetch LLM preferences"); + } + + return await response.json(); +};