This commit is contained in:
Gilang Javier 2026-09-26 20:20:51 +00:00 • committed by GitHub
commit d701b9e25d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -443,8 +443,18 @@ export const apiSchema = createSchema({
},
})
function normalizeBackendV3BaseURL(rawBaseURL: string): string {
// Allow passing either "https://api.supermemory.ai" or "https://api.supermemory.ai/v3"
// (and tolerate trailing slashes) without accidentally producing "/v3/v3".
const trimmed = rawBaseURL.replace(/\/+$/, "")
return trimmed.endsWith("/v3") ? trimmed : `${trimmed}/v3`
}
const backendBaseURL =
process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"
export const $fetch = createFetch({
baseURL: `${process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"}/v3`,
baseURL: normalizeBackendV3BaseURL(backendBaseURL),
credentials: "include",
headers: { "X-App-Source": "nova" },
onRequest: (context: { headers: Headers }) => {

View file

@ -10,8 +10,18 @@ import {
} from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
function normalizeBackendBaseURL(rawBaseURL: string): string {
// Accept either "https://api.supermemory.ai" or "https://api.supermemory.ai/v3".
// Auth endpoints are mounted at the root base (not under /v3).
const trimmed = rawBaseURL.replace(/\/+$/, "")
return trimmed.endsWith("/v3") ? trimmed.slice(0, -3) : trimmed
}
const backendBaseURL =
process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai"
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_BACKEND_URL ?? "https://api.supermemory.ai",
baseURL: normalizeBackendBaseURL(backendBaseURL),
fetchOptions: {
credentials: "include",
headers: { "X-App-Source": "nova" },