feat: implement workspace session management and enhance API proxy handling
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
import { createApi, } from "@garage/api";
|
||||
import { useAuthStore } from "./stores/auth-store";
|
||||
import { getAuthCookies } from "@/modules/auth/auth.actions";
|
||||
import { createApi } from "@garage/api"
|
||||
import { getAuthCookies, getWorkspaceContext } from "@/modules/auth/auth.actions"
|
||||
|
||||
/**
|
||||
* Returns an authenticated API client for server-side use (server actions, RSC).
|
||||
*
|
||||
* Server-side calls bypass the /api/proxy route — the server already has
|
||||
* cookie access and can talk to the workspace's repareenew install directly.
|
||||
* Browser-side code should use the singleton `api` from @garage/api, which
|
||||
* defaults to baseUrl="/api/proxy" and gets workspace context from cookies
|
||||
* via the proxy route.
|
||||
*/
|
||||
export const getAuthApi = async () => {
|
||||
const { token } = await getAuthCookies();
|
||||
console.log(`Auth Token: ${token}`);
|
||||
const api = createApi({ headers: token ? { Authorization: `Bearer ${token}` } : undefined });
|
||||
return api;
|
||||
const { token } = await getAuthCookies()
|
||||
const { apiBase, workspaceUuid } = await getWorkspaceContext()
|
||||
|
||||
const headers: Record<string, string> = {}
|
||||
if (token) headers.Authorization = `Bearer ${token}`
|
||||
if (workspaceUuid) headers["X-Workspace-UUID"] = workspaceUuid
|
||||
|
||||
return createApi({
|
||||
baseUrl: apiBase,
|
||||
headers: Object.keys(headers).length ? headers : undefined,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import Link from "next/link"
|
||||
import { AlertCircle, ExternalLink } from "lucide-react"
|
||||
|
||||
export function WorkspaceSessionMissing({ saasUrl }: { saasUrl?: string }) {
|
||||
const fallbackUrl = saasUrl ?? process.env.NEXT_PUBLIC_SAAS_URL ?? "/"
|
||||
return (
|
||||
<div className="min-h-[60vh] flex items-center justify-center p-6">
|
||||
<div className="max-w-md w-full text-center space-y-3 bg-white rounded-xl shadow-sm border p-8">
|
||||
<AlertCircle className="size-10 mx-auto text-amber-500" />
|
||||
<h1 className="text-lg font-semibold">Workspace session not found</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Please open your garage from the SaaS dashboard to get a fresh handoff link.
|
||||
</p>
|
||||
<Link
|
||||
href={fallbackUrl}
|
||||
className="inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm border bg-white hover:bg-muted/40 transition"
|
||||
>
|
||||
<ExternalLink className="size-3.5" />
|
||||
Back to SaaS dashboard
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user