Add credentials: 'include' to chat completion fetch to enable cookie-based validation #5263

Closed
opened 2025-11-11 16:15:52 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @entanglesoftware on GitHub (May 21, 2025).

Summary

Update the chat modal so that AJAX (fetch) requests to /api/chat include credentials: 'include' in the fetch options. This ensures cookies are sent with the request and allows backend validation using session or authentication cookies.

Details

  • In src/lib/components/chat/Chat.svelte, locate the function responsible for calling the chat completion endpoint (e.g., generateChatCompletion).
  • Update the fetch call to /api/chat (or equivalent) to include credentials: 'include'.
  • This enables cookies to be sent along with the AJAX request, supporting validation and authentication on the backend.

Example Change

 fetch('/api/chat', {
   method: 'POST',
   headers: { ... },
   body: JSON.stringify(payload),
+  credentials: 'include'
 })

Motivation

Some deployments require validation and authentication via cookies rather than only using bearer tokens. This change provides compatibility for such setups.

Impact

  • Only the fetch request for chat completion is affected.
  • No breaking changes; authentication via headers will still work.

If you need this change for other endpoints as well, please specify!

Originally created by @entanglesoftware on GitHub (May 21, 2025). ## Summary Update the chat modal so that AJAX (fetch) requests to `/api/chat` include `credentials: 'include'` in the fetch options. This ensures cookies are sent with the request and allows backend validation using session or authentication cookies. ## Details - In `src/lib/components/chat/Chat.svelte`, locate the function responsible for calling the chat completion endpoint (e.g., `generateChatCompletion`). - Update the fetch call to `/api/chat` (or equivalent) to include `credentials: 'include'`. - This enables cookies to be sent along with the AJAX request, supporting validation and authentication on the backend. ### Example Change ```diff fetch('/api/chat', { method: 'POST', headers: { ... }, body: JSON.stringify(payload), + credentials: 'include' }) ``` ## Motivation Some deployments require validation and authentication via cookies rather than only using bearer tokens. This change provides compatibility for such setups. ## Impact - Only the fetch request for chat completion is affected. - No breaking changes; authentication via headers will still work. --- If you need this change for other endpoints as well, please specify!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#5263