mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-01 02:01:40 +00:00
fix(lib): normalize backend baseURL to avoid /v3/v3
Prevents invalid API URLs when NEXT_PUBLIC_BACKEND_URL already includes /v3 (fixes dashboard JSON parse errors).
This commit is contained in:
parent
fe5d16509a
commit
cbe6075fc8
2 changed files with 22 additions and 2 deletions
|
|
@ -227,8 +227,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",
|
||||
retry: {
|
||||
attempts: 3,
|
||||
|
|
|
|||
|
|
@ -9,8 +9,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",
|
||||
throw: true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue