Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/cli/src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,26 @@ export async function getRequestAuthHeaders(): Promise<Record<string, string>> {
throw new Error("Session not found. Please login again.");
}

// Extract tokens from session
const { access_token, refresh_token } = session;

if (!access_token || !refresh_token) {
throw new Error("Session expired. Please login again.");
}

// Create Supabase client (no cookies needed for this local op)
const REFRESH_BUFFER_SECONDS = 60;
let needsRefresh = true;
try {
const { exp } = decodeJwt(access_token);
needsRefresh = !exp ||
exp <= Math.floor(Date.now() / 1000) + REFRESH_BUFFER_SECONDS;
} catch {
needsRefresh = true;
}

if (!needsRefresh) {
return { Authorization: `Bearer ${access_token}` };
}

const { client: supabase, responseHeaders } = createClient();

const { data, error } = await supabase.auth.setSession({
Expand Down
Loading