@@ -35,6 +35,7 @@ import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
35
35
import { getEmbedConfig , setEmbedConfig } from './embedConfig' ;
36
36
import { getQueryParamString , getValueFromWindow , storeValueInWindow } from '../utils' ;
37
37
import { resetAllCachedServices } from '../utils/resetServices' ;
38
+ import { isBrowser } from '../utils' ;
38
39
39
40
const CONFIG_DEFAULTS : Partial < EmbedConfig > = {
40
41
loginFailedMessage : 'Not logged in' ,
@@ -238,33 +239,51 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
238
239
) ;
239
240
240
241
setGlobalLogLevelOverride ( embedConfig . logLevel ) ;
241
- registerReportingObserver ( ) ;
242
+
243
+ // Only register browser-specific observers when in browser
244
+ if ( isBrowser ( ) ) {
245
+ registerReportingObserver ( ) ;
246
+ }
242
247
243
248
const authEE = new EventEmitter < AuthStatus | AuthEvent > ( ) ;
244
249
setAuthEE ( authEE ) ;
245
- handleAuth ( ) ;
246
-
247
- console . log ( 'init mixpanel done' , getEmbedConfig ( ) ) ;
248
- alert ( "yaha tak to aa gya bhai bina error ke" ) ;
249
-
250
- const { password, ...configToTrack } = getEmbedConfig ( ) ;
251
- uploadMixpanelEvent ( MIXPANEL_EVENT . VISUAL_SDK_CALLED_INIT , {
252
- ...configToTrack ,
253
- usedCustomizationSheet : embedConfig . customizations ?. style ?. customCSSUrl != null ,
254
- usedCustomizationVariables : embedConfig . customizations ?. style ?. customCSS ?. variables != null ,
255
- usedCustomizationRules :
256
- embedConfig . customizations ?. style ?. customCSS ?. rules_UNSTABLE != null ,
257
- usedCustomizationStrings : ! ! embedConfig . customizations ?. content ?. strings ,
258
- usedCustomizationIconSprite : ! ! embedConfig . customizations ?. iconSpriteUrl ,
259
- } ) ;
250
+
251
+ // For SSR, we handle auth differently based on auth type
252
+ if ( embedConfig . authType === AuthType . TrustedAuthTokenCookieless ) {
253
+ // Cookieless auth can work in SSR
254
+ handleAuth ( ) ;
255
+ } else if ( isBrowser ( ) ) {
256
+ // Other auth types need browser capabilities
257
+ handleAuth ( ) ;
258
+ }
260
259
261
- if ( getEmbedConfig ( ) . callPrefetch ) {
262
- prefetch ( getEmbedConfig ( ) . thoughtSpotHost ) ;
260
+ // Skip browser-only operations when in SSR
261
+ if ( isBrowser ( ) ) {
262
+ console . log ( 'init mixpanel done' , getEmbedConfig ( ) ) ;
263
+ alert ( "yaha tak to aa gya bhai bina error ke" ) ;
264
+
265
+ const { password, ...configToTrack } = getEmbedConfig ( ) ;
266
+ uploadMixpanelEvent ( MIXPANEL_EVENT . VISUAL_SDK_CALLED_INIT , {
267
+ ...configToTrack ,
268
+ usedCustomizationSheet : embedConfig . customizations ?. style ?. customCSSUrl != null ,
269
+ usedCustomizationVariables : embedConfig . customizations ?. style ?. customCSS ?. variables != null ,
270
+ usedCustomizationRules :
271
+ embedConfig . customizations ?. style ?. customCSS ?. rules_UNSTABLE != null ,
272
+ usedCustomizationStrings : ! ! embedConfig . customizations ?. content ?. strings ,
273
+ usedCustomizationIconSprite : ! ! embedConfig . customizations ?. iconSpriteUrl ,
274
+ } ) ;
275
+
276
+ if ( getEmbedConfig ( ) . callPrefetch ) {
277
+ prefetch ( getEmbedConfig ( ) . thoughtSpotHost ) ;
278
+ }
263
279
}
264
280
265
- // Resolves the promise created in the initPromiseKey
266
- getValueFromWindow < InitFlagStore > ( initFlagKey ) . initPromiseResolve ( authEE ) ;
267
- getValueFromWindow < InitFlagStore > ( initFlagKey ) . isInitCalled = true ;
281
+ // Store initialization flag in appropriate storage (server or browser)
282
+ const initFlagStore = getValueFromWindow < InitFlagStore > ( initFlagKey ) ;
283
+ if ( initFlagStore ) {
284
+ initFlagStore . initPromiseResolve ( authEE ) ;
285
+ initFlagStore . isInitCalled = true ;
286
+ }
268
287
269
288
return authEE as AuthEventEmitter ;
270
289
} ;
0 commit comments