@lastbrain/ai-ui-core 1.0.47 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -77,10 +77,10 @@ export function createLBProxyHandler(config: LBProxyConfig = {}) {
77
77
 
78
78
  // Routes publiques qui ne nécessitent pas d'authentification
79
79
  const publicPaths = [
80
- "auth/login",
81
- "auth/session/create",
82
- "auth/session",
83
- "public/user/api-keys",
80
+ "public/login",
81
+ "public/status",
82
+ "auth/session/verify",
83
+ "auth/session/logout",
84
84
  ];
85
85
  const isPublicPath = publicPaths.some((p) => path.startsWith(p));
86
86
 
@@ -105,21 +105,30 @@ export function createLBProxyHandler(config: LBProxyConfig = {}) {
105
105
  }
106
106
 
107
107
  const authorization = request.headers.get("authorization");
108
+ const explicitApiKeyHeader = request.headers.get("x-lb-api-key");
109
+ const sessionToken = request.cookies.get(sessionCookieName)?.value;
108
110
  if (authorization) {
109
111
  headers["Authorization"] = authorization;
110
112
  }
113
+ if (explicitApiKeyHeader) {
114
+ headers["x-lb-api-key"] = explicitApiKeyHeader;
115
+ }
116
+ if (sessionToken) {
117
+ // Always forward lb_session cookie to allow backend fallback auth,
118
+ // even when an Authorization header is present.
119
+ headers["Cookie"] = `${sessionCookieName}=${sessionToken}`;
120
+ }
111
121
 
112
122
  // Authentification : LB_API_KEY ou session cookie
113
- if (!authorization) {
123
+ if (!authorization && !explicitApiKeyHeader) {
114
124
  if (apiKey) {
125
+ headers["x-lb-api-key"] = apiKey;
115
126
  headers["Authorization"] = `Bearer ${apiKey}`;
116
127
  } else {
117
128
  // Lire le cookie de session
118
- const sessionToken = request.cookies.get(sessionCookieName)?.value;
119
129
  if (sessionToken) {
120
130
  // Envoyer le cookie à la fois comme Authorization ET comme Cookie
121
131
  headers["Authorization"] = `Bearer ${sessionToken}`;
122
- headers["Cookie"] = `${sessionCookieName}=${sessionToken}`;
123
132
  console.log("[LB Proxy] Forwarding session cookie:", {
124
133
  name: sessionCookieName,
125
134
  hasValue: !!sessionToken,
package/src/types/auth.ts CHANGED
@@ -11,6 +11,8 @@ export interface LBAuthConfig {
11
11
  baseUrl?: string;
12
12
  /** Clé API LastBrain (côté serveur uniquement) */
13
13
  apiKey?: string;
14
+ /** API key sélectionnée (utile en mode supabase) */
15
+ selectedApiKeyId?: string;
14
16
  /** Mode d'authentification */
15
17
  mode?: "env-key" | "session" | "auto";
16
18
  }
@@ -124,7 +124,9 @@ export interface AiStatus {
124
124
 
125
125
  export interface ClientConfig {
126
126
  baseUrl: string;
127
- apiKeyId: string;
127
+ apiKeyId?: string;
128
+ sessionToken?: string;
129
+ credentials?: RequestCredentials;
128
130
  timeout?: number;
129
131
  retries?: number;
130
132
  }