diff --git a/src-tauri/capabilities/migrated.json b/src-tauri/capabilities/migrated.json index b55bbbb..29b249f 100644 --- a/src-tauri/capabilities/migrated.json +++ b/src-tauri/capabilities/migrated.json @@ -6,6 +6,11 @@ "main" ], "permissions": [ - "core:default" + "core:default", + "http:default", + { + "identifier": "http:default", + "allow": [{ "url": "https://**" }] + } ] } \ No newline at end of file diff --git a/utils/fetchWithApi.ts b/utils/fetchWithApi.ts index 4089db8..f5236c7 100644 --- a/utils/fetchWithApi.ts +++ b/utils/fetchWithApi.ts @@ -1,6 +1,13 @@ import type { NitroFetchRequest, NitroFetchOptions } from "nitropack"; +import { fetch as tauriFetch, type ClientOptions } from '@tauri-apps/plugin-http'; -export default async (path: string, options: NitroFetchOptions = {}) => { +declare global { + interface Window { + __TAURI_INTERNALS__: Record; + } +} + +export default async (path: string, options: NitroFetchOptions | (RequestInit & ClientOptions) = {}) => { console.log("path received:", path); if (!path.startsWith("/")) { path = "/" + path; @@ -18,7 +25,7 @@ export default async (path: string, options: NitroFetchOptions = {}) return; } console.log("path:", path) - const { revoke, refresh } = useAuth(); + const { logout, refresh } = useAuth(); let headers: HeadersInit = {}; @@ -38,12 +45,24 @@ export default async (path: string, options: NitroFetchOptions = {}) }; } try { - console.log("fetching:", URL.parse(apiBase + path)); - const res = await $fetch(URL.parse(apiBase + path)!.href, { - ...options, - headers, - credentials: "include" - }); + let res; + if (window.__TAURI_INTERNALS__) { + // Use Tauri's HTTP client + console.log("USING TAURI'S FUCKING BITCHASS FETCH SHIT") + res = await tauriFetch(URL.parse(apiBase + path)!.href, { + ...options, + headers, + credentials: "include" + } as RequestInit & ClientOptions) + } else { + console.log("USING GOATED EPIC NUXT FETCH") + console.log("fetching:", URL.parse(apiBase + path)); + res = await $fetch(URL.parse(apiBase + path)!.href, { + ...options, + headers, + credentials: "include" + } as NitroFetchOptions); + } return res; } catch (error: any) { @@ -62,7 +81,7 @@ export default async (path: string, options: NitroFetchOptions = {}) console.log("Refresh returned 401"); reauthFailed = true; console.log("Revoking"); - await revoke(); + await logout(); console.log("Redirecting to login"); await navigateTo("/login"); console.log("redirected");