Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-18 18:06:45 +00:00
co-authored by renee-png
parent 6a9d118316
commit 539f18397c
@@ -0,0 +1,16 @@
import { createMiddleware } from "@tanstack/react-start";
import { supabase } from "./client";
// Client-side middleware for server functions: forwards the current
// Supabase access token as a Bearer Authorization header so that the
// server-side `requireSupabaseAuth` middleware can authenticate the request.
export const attachSupabaseAuth = createMiddleware({ type: "function" }).client(
async ({ next }) => {
const { data } = await supabase.auth.getSession();
const token = data.session?.access_token;
return next({
sendContext: {},
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
},
);