@@ -96,9 +96,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
9696
9797 const embedOtt = takeEmbedTokenFromUrl ( ) ;
9898
99- // Asked again on every use, so a session that arrives later — from the
100- // exchange, or from a login — reaches the socket and every other module.
101- // A declaration, not a const, so this block can stay above the auth module.
99+ // A declaration, not a const: this block sits above the auth module.
102100 function getToken ( ) : string | null {
103101 return userAuthModule . getToken ( ) ?? ( embedOtt ? null : getAccessToken ( ) ) ;
104102 }
@@ -122,9 +120,8 @@ export function createClient(config: CreateClientConfig): Base44Client {
122120 return socket ;
123121 } ;
124122
125- // Apps read getAccessToken() as they load and pass the result in as `token`,
126- // so on an embedded load this is the OTT: proof of an identity, not one to
127- // send as a bearer. The exchange below is what turns it into a session.
123+ // Apps pass getAccessToken() in as `token`, which in a frame is the OTT —
124+ // what the exchange trades for a session, never a bearer itself.
128125 const token = embedOtt ? undefined : config . token ;
129126
130127 const headers = {
@@ -192,9 +189,8 @@ export function createClient(config: CreateClientConfig): Base44Client {
192189 serverUrl,
193190 token,
194191 embedded : Boolean ( embedOtt ) ,
195- // The socket carries its token on the handshake, so an identity change
196- // only reaches it by opening a new connection — or, on logout, by
197- // dropping the one still running as the user who just left.
192+ // The socket carries its token on the handshake, so it can only pick a
193+ // new one up by redialling — or, on logout, by dropping what it has.
198194 onSessionChange : ( hasSession ) =>
199195 hasSession ? socket ?. reconnect ( ) : socket ?. disconnect ( ) ,
200196 }
@@ -204,8 +200,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
204200 // requests during construction (notably analytics, which fires an init
205201 // event whose flush calls auth.me()). Without this, the first User/me
206202 // request is built before setToken runs and goes out unauthenticated.
207- // Not in a frame: a stored token there belongs to an earlier visitor, not to
208- // this session, which only the exchange below can produce.
203+ // Not in a frame: a stored token there belongs to an earlier visitor.
209204 if ( typeof window !== "undefined" && ! embedOtt ) {
210205 const accessToken = token || getAccessToken ( ) ;
211206 if ( accessToken ) {
@@ -217,18 +212,15 @@ export function createClient(config: CreateClientConfig): Base44Client {
217212 ? exchangeEmbedToken ( { serverUrl, appId, ott : embedOtt } )
218213 : null ;
219214
220- // Settles once the exchanged session is applied (memory only); at once
221- // otherwise. Never rejects: every request waits on it, so a failure here
222- // must not turn into a rejection on each of them.
215+ // Never rejects: every request waits on it, so one failure here must not
216+ // become a rejection on each of them.
223217 const authReady : Promise < void > = session
224218 ? session
225219 . then ( ( sessionToken ) => {
226220 if ( sessionToken ) {
227221 userAuthModule . setToken ( sessionToken , false ) ;
228222 return ;
229223 }
230- // The app is about to run anonymous. Say why, once, instead of
231- // leaving only the 401s that follow.
232224 const error = new Error (
233225 "Base44: the embed token was refused, so this app is not signed in." ,
234226 ) ;
@@ -241,8 +233,8 @@ export function createClient(config: CreateClientConfig): Base44Client {
241233 : Promise . resolve ( ) ;
242234
243235 if ( session ) {
244- // Requests issued during the exchange wait for it. Registered after createAxiosClient's
245- // interceptors so it runs first and the anonymous-visitor header sees the Authorization.
236+ // Registered after createAxiosClient's so it runs first (axios unshifts),
237+ // letting the anonymous-visitor header see the Authorization we just set .
246238 for ( const client of [ axiosClient , functionsAxiosClient ] ) {
247239 client . interceptors . request . use ( async ( requestConfig ) => {
248240 await authReady ;
@@ -316,8 +308,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
316308 getSocket,
317309 appId,
318310 serverUrl,
319- // Read synchronously, unlike everything else: these build a URL rather
320- // than issue a request, so during the exchange they see no token.
311+ // Sync, unlike everything else: these return a URL, not a promise.
321312 getToken,
322313 } ) ,
323314 aiGateway : createAiGatewayModule ( { serverUrl, getToken, appId } ) ,
@@ -366,9 +357,8 @@ export function createClient(config: CreateClientConfig): Base44Client {
366357 getSocket,
367358 appId,
368359 serverUrl,
369- // The user's token, as on the user-scoped module: the only thing this is
370- // read for is the `?token=` on a channel URL handed to that user, which
371- // the app's service credential must never end up in.
360+ // The user's token, deliberately: this is read only for the `?token=` on
361+ // a channel URL handed to that user. Never the service credential.
372362 getToken,
373363 } ) ,
374364 aiGateway : createAiGatewayModule ( {
0 commit comments