mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 03:20:46 +02:00
fix: send Supabase token on raw fetch in SaaS chat
This commit is contained in:
@@ -467,7 +467,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: getAuthHeaders(),
|
||||
headers: await getAuthHeaders(),
|
||||
credentials: "include",
|
||||
signal: controller.signal,
|
||||
},
|
||||
|
||||
@@ -100,8 +100,11 @@ async function refreshAuthToken(client: AxiosInstance): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Auth headers for raw fetch() calls (SSE streams, etc.). */
|
||||
export function getAuthHeaders(): Record<string, string> {
|
||||
/**
|
||||
* Auth headers for raw fetch() calls (SSE streams, etc.).
|
||||
* Async to match the SaaS override, which has to await the Supabase session.
|
||||
*/
|
||||
export async function getAuthHeaders(): Promise<Record<string, string>> {
|
||||
const headers: Record<string, string> = {};
|
||||
const jwt = getJwtTokenFromStorage();
|
||||
if (jwt) {
|
||||
@@ -117,8 +120,8 @@ export function getAuthHeaders(): Record<string, string> {
|
||||
export function setupApiInterceptors(client: AxiosInstance): void {
|
||||
// Install request interceptor to add JWT token
|
||||
client.interceptors.request.use(
|
||||
(config) => {
|
||||
const authHeaders = getAuthHeaders();
|
||||
async (config) => {
|
||||
const authHeaders = await getAuthHeaders();
|
||||
for (const [key, value] of Object.entries(authHeaders)) {
|
||||
if (!config.headers[key]) {
|
||||
config.headers[key] = value;
|
||||
|
||||
Reference in New Issue
Block a user