// auth-client.js
import { adminClient, organizationClient } from "better-auth/client/plugins";
import { nextCookies } from "better-auth/next-js";
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:3005",
plugins: [
adminClient(),
organizationClient(),
nextCookies(),
]
})
// api-fetch.ts
import { cookies } from "next/headers"
import { authClient } from "./auth-client"
export default async function apiFetch(url: string) {
const cookieStore = await cookies()
const cookieHeader = Array.from(cookieStore.getAll())
.map(({ name, value }) => `${name}=${value}`)
.join("; ");
const resp = authClient.$fetch(url, {
headers: {
// manual cookie included
Cookie: cookieHeader,
},
})
return resp
}
// auth-client.js
import { adminClient, organizationClient } from "better-auth/client/plugins";
import { nextCookies } from "better-auth/next-js";
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:3005",
plugins: [
adminClient(),
organizationClient(),
nextCookies(),
]
})
// api-fetch.ts
import { cookies } from "next/headers"
import { authClient } from "./auth-client"
export default async function apiFetch(url: string) {
const cookieStore = await cookies()
const cookieHeader = Array.from(cookieStore.getAll())
.map(({ name, value }) => `${name}=${value}`)
.join("; ");
const resp = authClient.$fetch(url, {
headers: {
// manual cookie included
Cookie: cookieHeader,
},
})
return resp
}