Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
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}` } : {},
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user