Enviar cookies entre orígenes diferentes
Traducción Beta No Oficial
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
Si tu API reside en un origen diferente al de tu front-end y deseas enviarle cookies, deberás habilitar CORS en tu servidor y enviar cookies con tus solicitudes proporcionando la opción {credentials: "include"} en fetch.
Los argumentos proporcionados a la función fetch que utiliza tRPC pueden modificarse de la siguiente manera.
app.tstsimport { createTRPCClient } from '@trpc/client';const client = createTRPCClient<AppRouter>({url: 'YOUR_SERVER_URL',fetch(url, options) {return fetch(url, {...options,credentials: 'include',});},});
app.tstsimport { createTRPCClient } from '@trpc/client';const client = createTRPCClient<AppRouter>({url: 'YOUR_SERVER_URL',fetch(url, options) {return fetch(url, {...options,credentials: 'include',});},});