Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(dashboard): keep admin and vendor logins independent (#1631)

Viktor Holik9f8f4cd9f77a
diff --git a/apps/admin-test/src/lib/client.ts b/apps/admin-test/src/lib/client.ts
index 078a11c58..65559e1b8 100644
--- a/apps/admin-test/src/lib/client.ts
+++ b/apps/admin-test/src/lib/client.ts
@@ -1,4 +1,5 @@
import { createClient, type InferClient } from "@mercurjs/client"
+import { getAuthHeaders } from "@mercurjs/admin"
import type { Routes } from '@acme/api/_generated'
declare const __BACKEND_URL__: string
@@ -6,6 +7,7 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
- }
+ credentials: 'omit',
+ },
+ headers: getAuthHeaders,
})
diff --git a/apps/docs/references/api/vendor/sellers/select-seller.mdx b/apps/docs/references/api/vendor/sellers/select-seller.mdx
index d9803c109..ea77fffc9 100644
--- a/apps/docs/references/api/vendor/sellers/select-seller.mdx
+++ b/apps/docs/references/api/vendor/sellers/select-seller.mdx
@@ -4,7 +4,7 @@ api: "POST /vendor/sellers/select"
description: "Set the active seller for the member's session."
---
-Stores the chosen seller in the session after verifying the member belongs to it.
+Verifies the member belongs to the chosen seller. For session-authenticated requests the seller is also stored in the session.
<Note>
Requires only the `Authorization` header. Session-based clients get the seller stored server-side; token-based clients should send `x-seller-id` on subsequent requests instead.
@@ -22,6 +22,10 @@ Stores the chosen seller in the session after verifying the member belongs to it
Whether the seller was selected.
</ResponseField>
+<ResponseField name="seller_id" type="string">
+ The selected seller's ID. Token-based clients send it as `x-seller-id` on subsequent requests.
+</ResponseField>
+
<RequestExample>
```bash cURL
curl -X POST 'http://localhost:9000/vendor/sellers/select' \
@@ -31,7 +35,7 @@ curl -X POST 'http://localhost:9000/vendor/sellers/select' \
```
```ts JS Client
-const { success } = await client.vendor.sellers.select.mutate({
+const { seller_id } = await client.vendor.sellers.select.mutate({
seller_id: "sel_01HXYZ",
})
```
@@ -39,6 +43,6 @@ const { success } = await client.vendor.sellers.select.mutate({
<ResponseExample>
```json 200
-{ "success": true }
+{ "success": true, "seller_id": "sel_01HXYZ" }
```
</ResponseExample>
diff --git a/apps/vendor/src/lib/client.ts b/apps/vendor/src/lib/client.ts
index bc9cd6700..609cd5ae9 100644
--- a/apps/vendor/src/lib/client.ts
+++ b/apps/vendor/src/lib/client.ts
@@ -1,4 +1,5 @@
import { createClient, type InferClient } from "@mercurjs/client"
+import { getAuthHeaders } from "@mercurjs/vendor"
import type { Routes } from '@mercurjs/core/_generated'
declare const __BACKEND_URL__: string
@@ -6,6 +7,7 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
- }
+ credentials: 'omit',
+ },
+ headers: getAuthHeaders,
})
diff --git a/claude-progress.md b/claude-progress.md
index 1ecdcd280..f9d0fb7d9 100644
--- a/claude-progress.md
+++ b/claude-progress.md
@@ -14,6 +14,18 @@ session detail aggressively. The per-spec source of truth lives in
`bun run test:integration:http -- <pattern>`
- **Current blocker**: none
+## Session — Panel auth collision, branch `fix/panel-auth-session-collision`
+
+Admin and vendor panels shared one API session cookie, so logging in to one logged the other out.
+Both panels now keep their JWT in origin-local storage and send `Authorization` (+ `x-seller-id`
+for vendor) via `getAuthHeaders` (exported from `@mercurjs/admin` / `@mercurjs/vendor`);
+`@mercurjs/client` gained a `headers` option; `POST /vendor/sellers/select` returns `seller_id` and
+only writes the session for session-authenticated callers. Host apps + `templates/basic` clients
+updated. Verified: `bun run build`, `test:integration:http -- panel-auth` (2/2). Not verified in a
+browser. **Open risk**: the messaging block's panel SSE (`EventSource` + `withCredentials`) can't
+send a bearer header, so it falls back to polling until it gets a token-exchange flow.
+Uncommitted.
+
## Session — Admin Inventory (MER-139), branch `feat/admin-inventory`
Spec + audit: `docs/specs/spec-3-admin-inventory/`. Implemented (type-clean; deps built; lint
diff --git a/integration-tests/http/auth/vendor/panel-auth.spec.ts b/integration-tests/http/auth/vendor/panel-auth.spec.ts
new file mode 100644
index 000000000..5a5e6af79
--- /dev/null
+++ b/integration-tests/http/auth/vendor/panel-auth.spec.ts
@@ -0,0 +1,88 @@
+import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
+import { MedusaContainer } from "@medusajs/framework/types"
+import {
+ adminHeaders,
+ createAdminUser,
+} from "../../../helpers/create-admin-user"
+import { createSellerUser } from "../../../helpers/create-seller-user"
+
+jest.setTimeout(50000)
+
+medusaIntegrationTestRunner({
+ testSuite: ({ getContainer, api, dbConnection }) => {
+ describe("Auth - admin and vendor panels side by side", () => {
+ let appContainer: MedusaContainer
+ let sellerId: string
+ let otherSellerId: string
+
+ const login = async (actorType: "user" | "member", email: string) => {
+ const response = await api.post(`/auth/${actorType}/emailpass`, {
+ email,
+ password: "somepassword",
+ })
+
+ return { headers: { authorization: `Bearer ${response.data.token}` } }
+ }
+
+ beforeAll(async () => {
+ appContainer = getContainer()
+ })
+
+ beforeEach(async () => {
+ await createAdminUser(dbConnection, adminHeaders, appContainer)
+
+ const result = await createSellerUser(appContainer, {
+ email: "[email protected]",
+ name: "Alpha Store",
+ })
+ sellerId = result.seller.id
+
+ const other = await createSellerUser(appContainer, {
+ email: "[email protected]",
+ name: "Beta Store",
+ })
+ otherSellerId = other.seller.id
+ })
+
+ it("keeps the admin authenticated after a vendor login", async () => {
+ const admin = await login("user", "[email protected]")
+
+ const before = await api.get(`/admin/users/me`, admin)
+ expect(before.status).toEqual(200)
+
+ const member = await login("member", "[email protected]")
+
+ const selected = await api.post(
+ `/vendor/sellers/select`,
+ { seller_id: sellerId },
+ member
+ )
+ expect(selected.status).toEqual(200)
+ expect(selected.data).toEqual({ success: true, seller_id: sellerId })
+ expect(selected.headers["set-cookie"]).toBeUndefined()
+
+ const me = await api.get(`/vendor/members/me`, {
+ headers: { ...member.headers, "x-seller-id": sellerId },
+ })
+ expect(me.status).toEqual(200)
+
+ const after = await api.get(`/admin/users/me`, admin)
+ expect(after.status).toEqual(200)
+ expect(after.data.user.email).toEqual("[email protected]")
+ })
+
+ it("rejects selecting a seller the member does not belong to", async () => {
+ const member = await login("member", "[email protected]")
+
+ const response = await api
+ .post(`/vendor/sellers/select`, { seller_id: otherSellerId }, member)
+ .catch((e) => e.response)
+
+ expect(response.status).toEqual(400)
+ expect(response.data.message).toEqual(
+ "You are not a member of this seller account"
+ )
+ })
+ })
+ },
+})
diff --git a/packages/admin/src/hooks/api/auth.tsx b/packages/admin/src/hooks/api/auth.tsx
index a799ea189..a1f58a2da 100644
--- a/packages/admin/src/hooks/api/auth.tsx
+++ b/packages/admin/src/hooks/api/auth.tsx
@@ -4,7 +4,7 @@ import {
InferClientOutput,
} from "@mercurjs/client"
import { UseMutationOptions, useMutation } from "@tanstack/react-query"
-import { sdk } from "../../lib/client"
+import { clearAuthToken, sdk, setAuthToken } from "../../lib/client"
export const useSignInWithEmailPass = (
options?: UseMutationOptions<
@@ -24,13 +24,7 @@ export const useSignInWithEmailPass = (
...payload,
})) as { token: string }
- await sdk.auth.session.mutate({
- fetchOptions: {
- headers: {
- Authorization: `Bearer ${data.token}`,
- },
- },
- })
+ setAuthToken(data.token)
return data
},
@@ -93,12 +87,12 @@ export const useResetPasswordForEmailPass = (
export const useLogout = (
options?: UseMutationOptions<
- InferClientOutput<typeof sdk.auth.session.delete>,
+ void,
ClientError
>
) => {
return useMutation({
- mutationFn: () => sdk.auth.session.delete({}),
+ mutationFn: async () => clearAuthToken(),
...options,
})
}
diff --git a/packages/admin/src/index.ts b/packages/admin/src/index.ts
index bb2ac363c..2b91838ca 100644
--- a/packages/admin/src/index.ts
+++ b/packages/admin/src/index.ts
@@ -36,4 +36,6 @@ export type {
PermissionMap,
PermissionRight,
RouteHandle,
-} from '@mercurjs/dashboard-sdk'
\ No newline at end of file
+} from '@mercurjs/dashboard-sdk'
+
+export { getAuthHeaders } from './lib/client/auth-token'
diff --git a/packages/admin/src/lib/client/auth-token.ts b/packages/admin/src/lib/client/auth-token.ts
new file mode 100644
index 000000000..68af12da6
--- /dev/null
+++ b/packages/admin/src/lib/client/auth-token.ts
@@ -0,0 +1,31 @@
+const AUTH_TOKEN_KEY = 'mercur_admin_auth_token'
+
+const read = (key: string) => {
+ try {
+ return localStorage.getItem(key)
+ } catch {
+ return null
+ }
+}
+
+const write = (key: string, value: string | null) => {
+ try {
+ if (value === null) {
+ localStorage.removeItem(key)
+ } else {
+ localStorage.setItem(key, value)
+ }
+ } catch {
+ return
+ }
+}
+
+export const getAuthToken = () => read(AUTH_TOKEN_KEY)
+export const setAuthToken = (token: string) => write(AUTH_TOKEN_KEY, token)
+export const clearAuthToken = () => write(AUTH_TOKEN_KEY, null)
+
+export const getAuthHeaders = (): Record<string, string> => {
+ const token = getAuthToken()
+
+ return token ? { Authorization: `Bearer ${token}` } : {}
+}
diff --git a/packages/admin/src/lib/client/client.ts b/packages/admin/src/lib/client/client.ts
index 08f5f5447..07787f2f9 100644
--- a/packages/admin/src/lib/client/client.ts
+++ b/packages/admin/src/lib/client/client.ts
@@ -3,14 +3,16 @@ import { Routes } from '@mercurjs/core/_generated'
import config from 'virtual:mercur/config'
import { assetUrl } from '../../utils/asset-url'
+import { clearAuthToken, getAuthHeaders } from './auth-token'
export const backendUrl = config.backendUrl ?? 'http://localhost:9000'
export const sdk: InferClient<Routes> = createClient({
baseUrl: backendUrl,
fetchOptions: {
- credentials: 'include',
+ credentials: 'omit',
},
+ headers: getAuthHeaders,
})
export const fetchQuery = async (
@@ -55,9 +57,10 @@ export const fetchQuery = async (
`${backendUrl}${url}${params ? `?${params}` : ''}`,
{
method,
- credentials: 'include',
+ credentials: 'omit',
headers: {
'Content-Type': 'application/json',
+ ...getAuthHeaders(),
...headers,
},
body: body ? JSON.stringify(body) : null,
@@ -68,6 +71,7 @@ export const fetchQuery = async (
const errorData = await response.json()
if (response.status === 401) {
+ clearAuthToken()
window.location.href = `${assetUrl('/login')}?reason=Unauthorized`
return
}
diff --git a/packages/admin/src/lib/client/index.ts b/packages/admin/src/lib/client/index.ts
index a5017494f..328eb8a42 100644
--- a/packages/admin/src/lib/client/index.ts
+++ b/packages/admin/src/lib/client/index.ts
@@ -1 +1,2 @@
export * from "./client"
+export * from "./auth-token"
diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts
index b478098c0..b3b29bf0c 100644
--- a/packages/client/src/index.ts
+++ b/packages/client/src/index.ts
@@ -72,7 +72,7 @@ const toFormData = (payload: Record<string, any>): FormData => {
};
export function createClient(options: ClientOptions) {
- const { baseUrl, fetchOptions: defaultFetchOptions } = options;
+ const { baseUrl, fetchOptions: defaultFetchOptions, headers: resolveHeaders } = options;
return createRecursiveProxy((path, args) => {
const action = path.pop() as ActionType;
@@ -129,6 +129,7 @@ export function createClient(options: ClientOptions) {
const headers = new Headers({
...defaultHeaders,
...defaultFetchOptions?.headers,
+ ...resolveHeaders?.(),
...inputFetchOptions?.headers,
});
diff --git a/packages/client/src/types/client.ts b/packages/client/src/types/client.ts
index 4a728483b..a80aa7e1b 100644
--- a/packages/client/src/types/client.ts
+++ b/packages/client/src/types/client.ts
@@ -5,6 +5,7 @@ export type ActionType = "query" | "mutate" | "delete";
export type ClientOptions = {
baseUrl: string;
fetchOptions?: RequestInit;
+ headers?: () => Record<string, string>;
};
type AddParamsToFn<Fn, TParams> =
diff --git a/packages/core/src/api/vendor/sellers/select/route.ts b/packages/core/src/api/vendor/sellers/select/route.ts
index ae3122533..76c109399 100644
--- a/packages/core/src/api/vendor/sellers/select/route.ts
+++ b/packages/core/src/api/vendor/sellers/select/route.ts
@@ -37,7 +37,9 @@ export const POST = async (
)
}
- req.session.seller_id = seller_id
+ if (req.session?.auth_context) {
+ req.session.seller_id = seller_id
+ }
- res.json({ success: true })
+ res.json({ success: true, seller_id })
}
diff --git a/packages/registry/src/messaging/admin/lib/client.ts b/packages/registry/src/messaging/admin/lib/client.ts
index 67eba000c..67fc100fb 100644
--- a/packages/registry/src/messaging/admin/lib/client.ts
+++ b/packages/registry/src/messaging/admin/lib/client.ts
@@ -7,6 +7,6 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
+ credentials: 'omit',
},
})
diff --git a/packages/registry/src/messaging/vendor/lib/client.ts b/packages/registry/src/messaging/vendor/lib/client.ts
index 018fdf2a0..1b7217cd1 100644
--- a/packages/registry/src/messaging/vendor/lib/client.ts
+++ b/packages/registry/src/messaging/vendor/lib/client.ts
@@ -7,6 +7,6 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
+ credentials: 'omit',
},
})
diff --git a/packages/registry/src/vendor-notifications/vendor/widgets/notifications.tsx b/packages/registry/src/vendor-notifications/vendor/widgets/notifications.tsx
index 55b678694..8becc025c 100644
--- a/packages/registry/src/vendor-notifications/vendor/widgets/notifications.tsx
+++ b/packages/registry/src/vendor-notifications/vendor/widgets/notifications.tsx
@@ -7,6 +7,7 @@ import { clx, Drawer, Heading, IconButton, Text } from "@medusajs/ui"
import { useQuery } from "@tanstack/react-query"
import { useEffect, useState } from "react"
import { defineWidgetConfig } from "@mercurjs/dashboard-sdk"
+import { getAuthHeaders } from "@mercurjs/vendor"
import {
FilePreview,
InfiniteList,
@@ -59,7 +60,7 @@ const fetchNotifications = async (
const response = await fetch(
`${__BACKEND_URL__}/vendor/notifications?${search.toString()}`,
- { credentials: "include" }
+ { credentials: "omit", headers: getAuthHeaders() }
)
if (!response.ok) {
diff --git a/packages/vendor/src/hooks/api/auth.tsx b/packages/vendor/src/hooks/api/auth.tsx
index 7f913e52b..f54d62e79 100644
--- a/packages/vendor/src/hooks/api/auth.tsx
+++ b/packages/vendor/src/hooks/api/auth.tsx
@@ -4,7 +4,12 @@ import {
InferClientOutput,
} from "@mercurjs/client";
import { UseMutationOptions, useMutation } from "@tanstack/react-query";
-import { sdk } from "../../lib/client";
+import {
+ clearAuthToken,
+ clearSellerId,
+ sdk,
+ setAuthToken,
+} from "../../lib/client";
export const useSignInWithEmailPass = (
options?: UseMutationOptions<
@@ -24,13 +29,8 @@ export const useSignInWithEmailPass = (
...payload,
})) as { token: string };
- await sdk.auth.session.mutate({
- fetchOptions: {
- headers: {
- Authorization: `Bearer ${data.token}`,
- },
- },
- });
+ clearSellerId();
+ setAuthToken(data.token);
return data;
},
@@ -61,15 +61,10 @@ export const useSignUpWithEmailPass = (
...payload,
}),
onSuccess: async (data, variables, context) => {
- options?.onSuccess?.(data, variables, context);
+ clearSellerId();
+ setAuthToken((data as { token: string }).token);
- await sdk.auth.session.mutate({
- fetchOptions: {
- headers: {
- Authorization: `Bearer ${(data as { token: string }).token}`,
- },
- },
- });
+ options?.onSuccess?.(data, variables, context);
},
...options,
});
@@ -151,12 +146,15 @@ export const useResetPasswordForEmailPass = (
export const useLogout = (
options?: UseMutationOptions<
- InferClientOutput<typeof sdk.auth.session.delete>,
+ void,
ClientError
>,
) => {
return useMutation({
- mutationFn: () => sdk.auth.session.delete({}),
+ mutationFn: async () => {
+ clearAuthToken();
+ clearSellerId();
+ },
...options,
});
};
diff --git a/packages/vendor/src/hooks/api/sellers.tsx b/packages/vendor/src/hooks/api/sellers.tsx
index 385f31ae6..0041a4537 100644
--- a/packages/vendor/src/hooks/api/sellers.tsx
+++ b/packages/vendor/src/hooks/api/sellers.tsx
@@ -9,7 +9,7 @@ import {
useMutation,
useQuery,
} from "@tanstack/react-query";
-import { sdk } from "../../lib/client";
+import { sdk, setSellerId } from "../../lib/client";
import { queryClient } from "../../lib/query-client";
import { queryKeysFactory } from "../../lib/query-key-factory";
import { membersQueryKeys, useMe } from "./members";
@@ -80,9 +80,8 @@ export const useSelectSeller = (
return useMutation({
mutationFn: (payload) => sdk.vendor.sellers.select.mutate(payload),
onSuccess: (data, variables, context) => {
- queryClient.invalidateQueries({
- queryKey: membersQueryKeys.me(),
- });
+ setSellerId(variables.seller_id);
+ queryClient.invalidateQueries();
options?.onSuccess?.(data, variables, context);
},
...options,
diff --git a/packages/vendor/src/index.ts b/packages/vendor/src/index.ts
index 47eecc1ad..2202e47fa 100644
--- a/packages/vendor/src/index.ts
+++ b/packages/vendor/src/index.ts
@@ -5,3 +5,5 @@ export { TabbedForm, useTabbedForm } from './components/tabbed-form'
export type { TabDefinition } from './components/tabbed-form'
// Layout components
+
+export { getAuthHeaders } from './lib/client/auth-token'
diff --git a/packages/vendor/src/lib/client/auth-token.ts b/packages/vendor/src/lib/client/auth-token.ts
new file mode 100644
index 000000000..7f7e52fd0
--- /dev/null
+++ b/packages/vendor/src/lib/client/auth-token.ts
@@ -0,0 +1,42 @@
+const AUTH_TOKEN_KEY = 'mercur_vendor_auth_token'
+
+const SELLER_ID_KEY = 'mercur_vendor_seller_id'
+
+const read = (key: string) => {
+ try {
+ return localStorage.getItem(key)
+ } catch {
+ return null
+ }
+}
+
+const write = (key: string, value: string | null) => {
+ try {
+ if (value === null) {
+ localStorage.removeItem(key)
+ } else {
+ localStorage.setItem(key, value)
+ }
+ } catch {
+ return
+ }
+}
+
+export const getAuthToken = () => read(AUTH_TOKEN_KEY)
+export const setAuthToken = (token: string) => write(AUTH_TOKEN_KEY, token)
+export const clearAuthToken = () => write(AUTH_TOKEN_KEY, null)
+
+export const getSellerId = () => read(SELLER_ID_KEY)
+export const setSellerId = (sellerId: string) => write(SELLER_ID_KEY, sellerId)
+export const clearSellerId = () => write(SELLER_ID_KEY, null)
+
+export const getAuthHeaders = (): Record<string, string> => {
+ const token = getAuthToken()
+
+ const sellerId = getSellerId()
+
+ return {
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
+ ...(sellerId ? { 'x-seller-id': sellerId } : {}),
+ }
+}
diff --git a/packages/vendor/src/lib/client/client.ts b/packages/vendor/src/lib/client/client.ts
index 08f5f5447..07787f2f9 100644
--- a/packages/vendor/src/lib/client/client.ts
+++ b/packages/vendor/src/lib/client/client.ts
@@ -3,14 +3,16 @@ import { Routes } from '@mercurjs/core/_generated'
import config from 'virtual:mercur/config'
import { assetUrl } from '../../utils/asset-url'
+import { clearAuthToken, getAuthHeaders } from './auth-token'
export const backendUrl = config.backendUrl ?? 'http://localhost:9000'
export const sdk: InferClient<Routes> = createClient({
baseUrl: backendUrl,
fetchOptions: {
- credentials: 'include',
+ credentials: 'omit',
},
+ headers: getAuthHeaders,
})
export const fetchQuery = async (
@@ -55,9 +57,10 @@ export const fetchQuery = async (
`${backendUrl}${url}${params ? `?${params}` : ''}`,
{
method,
- credentials: 'include',
+ credentials: 'omit',
headers: {
'Content-Type': 'application/json',
+ ...getAuthHeaders(),
...headers,
},
body: body ? JSON.stringify(body) : null,
@@ -68,6 +71,7 @@ export const fetchQuery = async (
const errorData = await response.json()
if (response.status === 401) {
+ clearAuthToken()
window.location.href = `${assetUrl('/login')}?reason=Unauthorized`
return
}
diff --git a/packages/vendor/src/lib/client/index.ts b/packages/vendor/src/lib/client/index.ts
index a5017494f..328eb8a42 100644
--- a/packages/vendor/src/lib/client/index.ts
+++ b/packages/vendor/src/lib/client/index.ts
@@ -1 +1,2 @@
export * from "./client"
+export * from "./auth-token"
diff --git a/packages/vendor/src/pages/invite/invite.tsx b/packages/vendor/src/pages/invite/invite.tsx
index e23480be6..e605d6a88 100644
--- a/packages/vendor/src/pages/invite/invite.tsx
+++ b/packages/vendor/src/pages/invite/invite.tsx
@@ -27,7 +27,7 @@ import { useAcceptInvite } from "@hooks/api/invites";
import { assetUrl } from "@/utils/asset-url";
import { useSelectSeller } from "@hooks/api";
import { isFetchError } from "@lib/is-fetch-error";
-import { sdk } from "@lib/client";
+import { sdk, setAuthToken } from "@lib/client";
const CreateAccountBaseSchema = z.object({
email: z.string().email(),
@@ -277,14 +277,7 @@ const CreateView = ({
password: data.password,
});
- // Establish session with the fresh token
- await sdk.auth.session.mutate({
- fetchOptions: {
- headers: {
- Authorization: `Bearer ${freshToken}`,
- },
- },
- });
+ setAuthToken(freshToken);
toast.success(t("invite.toast.accepted"));
onSuccess();
diff --git a/templates/basic/apps/admin/src/lib/client.ts b/templates/basic/apps/admin/src/lib/client.ts
index 078a11c58..65559e1b8 100644
--- a/templates/basic/apps/admin/src/lib/client.ts
+++ b/templates/basic/apps/admin/src/lib/client.ts
@@ -1,4 +1,5 @@
import { createClient, type InferClient } from "@mercurjs/client"
+import { getAuthHeaders } from "@mercurjs/admin"
import type { Routes } from '@acme/api/_generated'
declare const __BACKEND_URL__: string
@@ -6,6 +7,7 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
- }
+ credentials: 'omit',
+ },
+ headers: getAuthHeaders,
})
diff --git a/templates/basic/apps/vendor/src/lib/client.ts b/templates/basic/apps/vendor/src/lib/client.ts
index 078a11c58..c0aca8edd 100644
--- a/templates/basic/apps/vendor/src/lib/client.ts
+++ b/templates/basic/apps/vendor/src/lib/client.ts
@@ -1,4 +1,5 @@
import { createClient, type InferClient } from "@mercurjs/client"
+import { getAuthHeaders } from "@mercurjs/vendor"
import type { Routes } from '@acme/api/_generated'
declare const __BACKEND_URL__: string
@@ -6,6 +7,7 @@ declare const __BACKEND_URL__: string
export const client: InferClient<Routes> = createClient({
baseUrl: __BACKEND_URL__,
fetchOptions: {
- credentials: 'include',
- }
+ credentials: 'omit',
+ },
+ headers: getAuthHeaders,
})