acsi-core 0.9.21 → 0.9.22

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.
@@ -4,8 +4,11 @@
4
4
  * This component handles MSAL redirect authentication flows by processing
5
5
  * the hash fragment in the URL before any router code can clear it.
6
6
  *
7
- * It must be rendered early in the app lifecycle, before the Router component,
8
- * to ensure it can process the redirect response from Microsoft.
7
+ * Uses useLayoutEffect to run synchronously before browser paint,
8
+ * ensuring it processes the redirect before React Router initializes.
9
+ *
10
+ * This component uses the singleton MSAL instance to avoid conflicts
11
+ * and ensure consistent state management.
9
12
  */
10
13
  declare const MSALRedirectHandler: () => null;
11
14
  export default MSALRedirectHandler;
@@ -22,6 +22,7 @@ export declare const msalConfig: (clientId: string, redirectUri: string) => {
22
22
  clientId: string;
23
23
  authority: string;
24
24
  redirectUri: string;
25
+ navigateToLoginRequestUrl: boolean;
25
26
  };
26
27
  cache: {
27
28
  cacheLocation: string;
package/dist/index.d.ts CHANGED
@@ -29,4 +29,5 @@ import CustomCreatable from "./components/Selects/CustomCreatable";
29
29
  import CustomSelectOption from "./components/Selects/CustomSelectOption";
30
30
  import utcToLocalTime from "./utils/utcToLocalTime";
31
31
  import Cookies from "js-cookie";
32
- export { setLoading, setLoadingPage, BASE_URL, OPENSALT_BASE_URL, ACCESS_TOKEN, DATE_TIME_MIN_VALUE, ORGANIZATION_TEAM, ORGANIZATION_TENANT, firstCheckToken, getImageUrl, Login, utcToLocalTime, getAccessToken, store, historyCore, setAlert, setUser, setTenant, setAddTenant, setTeam, setMenuCollapse, setIsRefetchSidebar, Loading, NotFound, LayoutContext, api, apiUpload, ConfirmDialog, CommonDialog, ToastContainer, toast, Role, Cookies, CustomPagination, useGoogleSignOut, CoreButton, CoreInput, CoreSelect, CoreCheckbox, CoreRadio, CoreError, CoreModal, CoreRange, CoreTextArea, CoreSearch, CoreSelectCompact, CoreInputCompact, CoreTitleInput, CoreTooltip, getErrorMessage, MarkdownLatexRender, MSALRedirectHandler, CustomSelect, CustomAsyncSelect, CustomCreatable, CustomSelectOption, GoogleOAuthProvider, useAmplitude, AmplitudeEvent, initializeAmplitude, initSentry };
32
+ import { getMSALInstance, initializeMSAL, handleMSALRedirect, isMSALRedirect, getAllAccounts, getActiveAccount } from "./utils/msalInstance";
33
+ export { setLoading, setLoadingPage, BASE_URL, OPENSALT_BASE_URL, ACCESS_TOKEN, DATE_TIME_MIN_VALUE, ORGANIZATION_TEAM, ORGANIZATION_TENANT, firstCheckToken, getImageUrl, Login, utcToLocalTime, getAccessToken, store, historyCore, setAlert, setUser, setTenant, setAddTenant, setTeam, setMenuCollapse, setIsRefetchSidebar, Loading, NotFound, LayoutContext, api, apiUpload, ConfirmDialog, CommonDialog, ToastContainer, toast, Role, Cookies, CustomPagination, useGoogleSignOut, CoreButton, CoreInput, CoreSelect, CoreCheckbox, CoreRadio, CoreError, CoreModal, CoreRange, CoreTextArea, CoreSearch, CoreSelectCompact, CoreInputCompact, CoreTitleInput, CoreTooltip, getErrorMessage, MarkdownLatexRender, MSALRedirectHandler, CustomSelect, CustomAsyncSelect, CustomCreatable, CustomSelectOption, GoogleOAuthProvider, useAmplitude, AmplitudeEvent, initializeAmplitude, initSentry, getMSALInstance, initializeMSAL, handleMSALRedirect, isMSALRedirect, getAllAccounts, getActiveAccount };
package/dist/index.js CHANGED
@@ -672,6 +672,25 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
672
672
 
673
673
  var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","microsoft_button":"_19ESb","box-field":"_2e9xO","box-input":"_3zXRp","box-text":"_8NJga","box-button-email":"_21FPk","box-signin-container":"_1QERu","box-signin-text":"_2-znH","box-signin-logo":"_1aB2m","box-right":"_3qndF","image-slideshow":"_1aM7m","active":"_Vx1zf","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r","width-400":"_4ehXP"};
674
674
 
675
+ // A type of promise-like that resolves synchronously and supports only one observer
676
+
677
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
678
+
679
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
680
+
681
+ // Asynchronously call a function and send errors to recovery continuation
682
+ function _catch(body, recover) {
683
+ try {
684
+ var result = body();
685
+ } catch(e) {
686
+ return recover(e);
687
+ }
688
+ if (result && result.then) {
689
+ return result.then(void 0, recover);
690
+ }
691
+ return result;
692
+ }
693
+
675
694
  function _arrayLikeToArray(r, a) {
676
695
  (null == a || a > r.length) && (a = r.length);
677
696
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -720,25 +739,6 @@ function _unsupportedIterableToArray(r, a) {
720
739
  }
721
740
  }
722
741
 
723
- // A type of promise-like that resolves synchronously and supports only one observer
724
-
725
- const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
726
-
727
- const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
728
-
729
- // Asynchronously call a function and send errors to recovery continuation
730
- function _catch(body, recover) {
731
- try {
732
- var result = body();
733
- } catch(e) {
734
- return recover(e);
735
- }
736
- if (result && result.then) {
737
- return result.then(void 0, recover);
738
- }
739
- return result;
740
- }
741
-
742
742
  var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
743
743
 
744
744
  var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
@@ -2185,7 +2185,8 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
2185
2185
  auth: {
2186
2186
  clientId: clientId,
2187
2187
  authority: "https://login.microsoftonline.com/common",
2188
- redirectUri: redirectUri
2188
+ redirectUri: redirectUri,
2189
+ navigateToLoginRequestUrl: false
2189
2190
  },
2190
2191
  cache: {
2191
2192
  cacheLocation: "sessionStorage",
@@ -2197,18 +2198,19 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
2197
2198
  if (containsPii) {
2198
2199
  return;
2199
2200
  }
2201
+ var prefix = '[MSAL]';
2200
2202
  switch (level) {
2201
2203
  case msalBrowser.LogLevel.Error:
2202
- console.error(message);
2204
+ console.error(prefix + " " + message);
2203
2205
  return;
2204
2206
  case msalBrowser.LogLevel.Info:
2205
- console.info(message);
2207
+ console.info(prefix + " " + message);
2206
2208
  return;
2207
2209
  case msalBrowser.LogLevel.Verbose:
2208
- console.debug(message);
2210
+ console.debug(prefix + " " + message);
2209
2211
  return;
2210
2212
  case msalBrowser.LogLevel.Warning:
2211
- console.warn(message);
2213
+ console.warn(prefix + " " + message);
2212
2214
  return;
2213
2215
  default:
2214
2216
  return;
@@ -2219,45 +2221,154 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
2219
2221
  };
2220
2222
  };
2221
2223
 
2224
+ var msalInstance = null;
2225
+ var isInitializing = false;
2226
+ var initPromise = null;
2227
+ var getMSALInstance = function getMSALInstance(clientId, redirectUri) {
2228
+ var finalClientId = clientId || MICROSOFT_CLIENT_ID;
2229
+ var finalRedirectUri = redirectUri || MICROSOFT_URL_DIRECT || window.location.origin;
2230
+ if (!finalClientId) {
2231
+ console.warn('[MSAL] Client ID not configured');
2232
+ return null;
2233
+ }
2234
+ if (!msalInstance) {
2235
+ msalInstance = new msalBrowser.PublicClientApplication(msalConfig(finalClientId, finalRedirectUri));
2236
+ }
2237
+ return msalInstance;
2238
+ };
2239
+ var initializeMSAL = function initializeMSAL(clientId, redirectUri) {
2240
+ try {
2241
+ var instance = getMSALInstance(clientId, redirectUri);
2242
+ if (!instance) {
2243
+ return Promise.resolve(null);
2244
+ }
2245
+ if (isInitializing && initPromise) {
2246
+ return Promise.resolve(initPromise.then(function () {
2247
+ return instance;
2248
+ }));
2249
+ }
2250
+ if (isInitializing) {
2251
+ return Promise.resolve(instance);
2252
+ }
2253
+ isInitializing = true;
2254
+ initPromise = instance.initialize().then(function () {
2255
+ isInitializing = false;
2256
+ return instance;
2257
+ })["catch"](function (error) {
2258
+ isInitializing = false;
2259
+ console.error('[MSAL] Initialization error:', error);
2260
+ throw error;
2261
+ });
2262
+ return Promise.resolve(initPromise);
2263
+ } catch (e) {
2264
+ return Promise.reject(e);
2265
+ }
2266
+ };
2267
+ var handleMSALRedirect = function handleMSALRedirect(clientId, redirectUri) {
2268
+ try {
2269
+ if (!window.location.hash) {
2270
+ return Promise.resolve(null);
2271
+ }
2272
+ var hashParams = new URLSearchParams(window.location.hash.substring(1));
2273
+ var hasMSALParams = hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
2274
+ if (!hasMSALParams) {
2275
+ return Promise.resolve(null);
2276
+ }
2277
+ return Promise.resolve(_catch(function () {
2278
+ return Promise.resolve(initializeMSAL(clientId, redirectUri)).then(function (instance) {
2279
+ return instance ? Promise.resolve(instance.handleRedirectPromise()) : null;
2280
+ });
2281
+ }, function (error) {
2282
+ console.error('[MSAL] Redirect handling error:', error);
2283
+ return null;
2284
+ }));
2285
+ } catch (e) {
2286
+ return Promise.reject(e);
2287
+ }
2288
+ };
2289
+ var isMSALRedirect = function isMSALRedirect() {
2290
+ if (!window.location.hash) {
2291
+ return false;
2292
+ }
2293
+ var hashParams = new URLSearchParams(window.location.hash.substring(1));
2294
+ return hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
2295
+ };
2296
+ var getAllAccounts = function getAllAccounts() {
2297
+ var instance = getMSALInstance();
2298
+ if (!instance) {
2299
+ return [];
2300
+ }
2301
+ return instance.getAllAccounts();
2302
+ };
2303
+ var getActiveAccount = function getActiveAccount() {
2304
+ var instance = getMSALInstance();
2305
+ if (!instance) {
2306
+ return null;
2307
+ }
2308
+ return instance.getActiveAccount();
2309
+ };
2310
+
2222
2311
  var MSALRedirectHandler = function MSALRedirectHandler() {
2223
- React.useEffect(function () {
2312
+ React.useLayoutEffect(function () {
2224
2313
  var handleRedirect = function handleRedirect() {
2225
2314
  try {
2226
- if (!window.location.hash) {
2315
+ if (!isMSALRedirect()) {
2227
2316
  return Promise.resolve();
2228
2317
  }
2229
- var hashParams = new URLSearchParams(window.location.hash.substring(1));
2230
- var hasMSALParams = hashParams.has('access_token') || hashParams.has('id_token') || hashParams.has('error') || hashParams.has('code');
2231
- if (!hasMSALParams) {
2232
- return Promise.resolve();
2233
- }
2234
- return Promise.resolve(_catch(function () {
2235
- var clientId = MICROSOFT_CLIENT_ID;
2236
- var redirectUri = MICROSOFT_URL_DIRECT || window.location.origin + window.location.pathname;
2237
- if (!clientId) {
2238
- return;
2239
- }
2240
- var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(clientId, redirectUri));
2241
- return Promise.resolve(msalInstance.initialize()).then(function () {
2242
- return Promise.resolve(msalInstance.handleRedirectPromise()).then(function (response) {
2243
- if (response) {
2244
- console.log('MSAL redirect handled successfully');
2245
- if (window.history.replaceState) {
2246
- window.history.replaceState(null, '', window.location.pathname + window.location.search);
2318
+ console.log('[MSAL] Redirect detected, processing...');
2319
+ console.log('[MSAL] Hash:', window.location.hash);
2320
+ console.log('[MSAL] Full URL:', window.location.href);
2321
+ var _temp = _catch(function () {
2322
+ return Promise.resolve(handleMSALRedirect()).then(function (response) {
2323
+ if (response && response.account) {
2324
+ console.log('[MSAL] Redirect handled successfully', {
2325
+ account: response.account.username,
2326
+ scopes: response.scopes
2327
+ });
2328
+ if (window.history.replaceState) {
2329
+ window.history.replaceState(null, '', window.location.pathname + window.location.search);
2330
+ }
2331
+ localStorage.setItem('MSAL_ACCOUNT', JSON.stringify(response.account));
2332
+ localStorage.setItem('MSAL_ACCESS_TOKEN', response.accessToken || '');
2333
+ localStorage.setItem('MSAL_LOGIN_PENDING', 'true');
2334
+ window.dispatchEvent(new CustomEvent('msal-login-success', {
2335
+ detail: {
2336
+ account: response.account,
2337
+ accessToken: response.accessToken,
2338
+ idToken: response.idToken
2247
2339
  }
2340
+ }));
2341
+ if (window.location.pathname.includes('/login')) {
2342
+ window.location.reload();
2248
2343
  } else {
2249
- if (hasMSALParams && window.history.replaceState) {
2250
- window.history.replaceState(null, '', window.location.pathname + window.location.search);
2344
+ window.location.href = '/dashboard';
2345
+ }
2346
+ } else {
2347
+ var hashParams = new URLSearchParams(window.location.hash.substring(1));
2348
+ var error = hashParams.get('error');
2349
+ var errorDescription = hashParams.get('error_description');
2350
+ if (error) {
2351
+ console.error('[MSAL] Authentication error:', error, errorDescription);
2352
+ if (error === 'access_denied') {
2353
+ console.error('[MSAL] User denied access or scopes not configured in Azure AD');
2251
2354
  }
2252
2355
  }
2253
- });
2356
+ if (window.history.replaceState) {
2357
+ window.history.replaceState(null, '', window.location.pathname + window.location.search);
2358
+ }
2359
+ }
2254
2360
  });
2255
2361
  }, function (error) {
2256
- console.error('Microsoft login error:', error);
2362
+ var _error$message;
2363
+ console.error('[MSAL] Redirect handling error:', error);
2364
+ if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'hash_empty_error' || error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('hash_empty')) {
2365
+ console.error('[MSAL] Hash was cleared before MSAL could process it. ' + 'This usually means code is running that clears the URL hash before MSAL handler executes.');
2366
+ }
2257
2367
  if (window.history.replaceState) {
2258
2368
  window.history.replaceState(null, '', window.location.pathname + window.location.search);
2259
2369
  }
2260
- }));
2370
+ });
2371
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
2261
2372
  } catch (e) {
2262
2373
  return Promise.reject(e);
2263
2374
  }
@@ -2465,11 +2576,120 @@ var BlockLogin = function BlockLogin(_ref) {
2465
2576
  return Promise.reject(e);
2466
2577
  }
2467
2578
  };
2579
+ var processMSALLogin = function processMSALLogin(account, accessToken) {
2580
+ try {
2581
+ return Promise.resolve(_catch(function () {
2582
+ dispatch(setLoading(true));
2583
+ var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
2584
+ var infoLogin = {
2585
+ firstName: fullName.split(' ').slice(0, -1).join(' '),
2586
+ lastName: fullName.split(' ').slice(-1).join(' '),
2587
+ fullName: fullName,
2588
+ imageUrl: "",
2589
+ email: (account === null || account === void 0 ? void 0 : account.username) || "",
2590
+ token: accessToken || "",
2591
+ googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
2592
+ role: role,
2593
+ type: TypeLogin.Microsoft
2594
+ };
2595
+ return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2596
+ var _authResult$data;
2597
+ if (((_authResult$data = authResult.data) === null || _authResult$data === void 0 ? void 0 : _authResult$data.id) == null) {
2598
+ dispatch(setLoading(false));
2599
+ alert("Please contact admin.");
2600
+ return;
2601
+ }
2602
+ localStorage.clear();
2603
+ var tokenJWT = authResult.data.token;
2604
+ trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
2605
+ eventName: exports.AmplitudeEvent.LOGIN,
2606
+ eventProperties: {
2607
+ email: (account === null || account === void 0 ? void 0 : account.username) || email,
2608
+ login_method: 'microsoft',
2609
+ user_role: authResult.data.role,
2610
+ success: true,
2611
+ timestamp: new Date().toISOString()
2612
+ }
2613
+ });
2614
+ if (role === "LandingPage") {
2615
+ CookieService.setAuthCookie({
2616
+ token: tokenJWT,
2617
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
2618
+ });
2619
+ var getRedirectUrl = function getRedirectUrl(role) {
2620
+ switch (role) {
2621
+ case "Admin":
2622
+ return ADMIN_ORIGIN;
2623
+ case "Teacher":
2624
+ return TEACHER_ORIGIN;
2625
+ default:
2626
+ return role + "." + REQUEST_ORIGIN;
2627
+ }
2628
+ };
2629
+ var redirectUrl = getRedirectUrl(authResult.data.role);
2630
+ window.location.href = redirectUrl + "/dashboard";
2631
+ dispatch(setLoading(false));
2632
+ } else {
2633
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2634
+ onNavigate("/dashboard");
2635
+ dispatch(setLoading(false));
2636
+ }
2637
+ });
2638
+ }, function (error) {
2639
+ console.error("[MSAL] Error processing login:", error);
2640
+ dispatch(setLoading(false));
2641
+ alert("An error occurred while processing your login. Please try again.");
2642
+ }));
2643
+ } catch (e) {
2644
+ return Promise.reject(e);
2645
+ }
2646
+ };
2468
2647
  React.useEffect(function () {
2469
2648
  if (role === "Teacher" || role === "LandingPage") {
2470
2649
  handleGetImage();
2471
2650
  }
2472
2651
  }, []);
2652
+ React.useEffect(function () {
2653
+ var handleMSALLoginSuccess = function handleMSALLoginSuccess(event) {
2654
+ try {
2655
+ var _event$detail = event.detail,
2656
+ account = _event$detail.account,
2657
+ accessToken = _event$detail.accessToken;
2658
+ var _temp2 = function () {
2659
+ if (account && accessToken) {
2660
+ localStorage.removeItem('MSAL_LOGIN_PENDING');
2661
+ return Promise.resolve(processMSALLogin(account, accessToken)).then(function () {});
2662
+ }
2663
+ }();
2664
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
2665
+ } catch (e) {
2666
+ return Promise.reject(e);
2667
+ }
2668
+ };
2669
+ var pendingLogin = localStorage.getItem('MSAL_LOGIN_PENDING');
2670
+ if (pendingLogin === 'true') {
2671
+ var accountStr = localStorage.getItem('MSAL_ACCOUNT');
2672
+ var accessToken = localStorage.getItem('MSAL_ACCESS_TOKEN');
2673
+ if (accountStr && accessToken) {
2674
+ try {
2675
+ var account = JSON.parse(accountStr);
2676
+ localStorage.removeItem('MSAL_LOGIN_PENDING');
2677
+ localStorage.removeItem('MSAL_ACCOUNT');
2678
+ localStorage.removeItem('MSAL_ACCESS_TOKEN');
2679
+ processMSALLogin(account, accessToken);
2680
+ } catch (error) {
2681
+ console.error('[MSAL] Error parsing stored account:', error);
2682
+ localStorage.removeItem('MSAL_LOGIN_PENDING');
2683
+ localStorage.removeItem('MSAL_ACCOUNT');
2684
+ localStorage.removeItem('MSAL_ACCESS_TOKEN');
2685
+ }
2686
+ }
2687
+ }
2688
+ window.addEventListener('msal-login-success', handleMSALLoginSuccess);
2689
+ return function () {
2690
+ window.removeEventListener('msal-login-success', handleMSALLoginSuccess);
2691
+ };
2692
+ }, []);
2473
2693
  var googleLogin = google.useGoogleLogin({
2474
2694
  onSuccess: function (tokenResponse) {
2475
2695
  try {
@@ -2501,8 +2721,8 @@ var BlockLogin = function BlockLogin(_ref) {
2501
2721
  };
2502
2722
  dispatch(setLoading(true));
2503
2723
  return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2504
- var _authResult$data;
2505
- if (((_authResult$data = authResult.data) === null || _authResult$data === void 0 ? void 0 : _authResult$data.id) == null) {
2724
+ var _authResult$data2;
2725
+ if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
2506
2726
  dispatch(setLoading(false));
2507
2727
  alert("Please contact admin.");
2508
2728
  return;
@@ -2555,84 +2775,27 @@ var BlockLogin = function BlockLogin(_ref) {
2555
2775
  });
2556
2776
  var fnLoginMicrosoft = function fnLoginMicrosoft() {
2557
2777
  try {
2558
- var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
2559
- if (!msalInstance) {
2560
- console.error("MSAL instance not initialized");
2561
- return Promise.resolve();
2562
- }
2563
2778
  return Promise.resolve(_catch(function () {
2564
- return Promise.resolve(msalInstance.initialize()).then(function () {
2779
+ var msalInstance = getMSALInstance(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT);
2780
+ if (!msalInstance) {
2781
+ console.error("[MSAL] Instance not initialized - check client ID configuration");
2782
+ alert("Microsoft login is not configured. Please contact admin.");
2783
+ return;
2784
+ }
2785
+ return Promise.resolve(initializeMSAL(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT)).then(function () {
2565
2786
  var loginRequest = {
2566
- scopes: ["openid", "profile", "email"]
2567
- };
2568
- var silentRequest = _extends$1({}, loginRequest, {
2787
+ scopes: ["openid", "profile", "User.Read"],
2569
2788
  prompt: "select_account"
2570
- });
2571
- return Promise.resolve(msalInstance.loginPopup(silentRequest)).then(function (response) {
2572
- return function () {
2573
- if (response && response.account) {
2574
- var account = response.account;
2575
- var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
2576
- var infoLogin = {
2577
- firstName: fullName.split(' ').slice(0, -1).join(' '),
2578
- lastName: fullName.split(' ').slice(-1).join(' '),
2579
- fullName: fullName,
2580
- imageUrl: "",
2581
- email: (account === null || account === void 0 ? void 0 : account.username) || "",
2582
- token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
2583
- googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
2584
- role: role,
2585
- type: TypeLogin.Microsoft
2586
- };
2587
- dispatch(setLoading(true));
2588
- return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2589
- var _authResult$data2;
2590
- if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
2591
- dispatch(setLoading(false));
2592
- alert("Please contact admin.");
2593
- return;
2594
- }
2595
- localStorage.clear();
2596
- var tokenJWT = authResult.data.token;
2597
- trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
2598
- eventName: exports.AmplitudeEvent.LOGIN,
2599
- eventProperties: {
2600
- email: email,
2601
- login_method: 'google',
2602
- user_role: authResult.data.role,
2603
- success: true,
2604
- timestamp: new Date().toISOString()
2605
- }
2606
- });
2607
- if (role === "LandingPage") {
2608
- CookieService.setAuthCookie({
2609
- token: tokenJWT,
2610
- expiresAt: Date.now() + 24 * 60 * 60 * 1000
2611
- });
2612
- var getRedirectUrl = function getRedirectUrl(role) {
2613
- switch (role) {
2614
- case "Admin":
2615
- return ADMIN_ORIGIN;
2616
- case "Teacher":
2617
- return TEACHER_ORIGIN;
2618
- default:
2619
- return role + "." + REQUEST_ORIGIN;
2620
- }
2621
- };
2622
- var redirectUrl = getRedirectUrl(authResult.data.role);
2623
- window.location.href = redirectUrl + "/dashboard";
2624
- dispatch(setLoading(false));
2625
- }
2626
- localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2627
- onNavigate("/dashboard");
2628
- dispatch(setLoading(false));
2629
- });
2630
- }
2631
- }();
2632
- });
2789
+ };
2790
+ return Promise.resolve(msalInstance.loginRedirect(loginRequest)).then(function () {});
2633
2791
  });
2634
2792
  }, function (error) {
2635
- console.error("Microsoft login error:", error);
2793
+ var _error$message;
2794
+ console.error("[MSAL] Microsoft login error:", error);
2795
+ if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'popup_window_error' || error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('popup')) {
2796
+ console.error("[MSAL] Popup blocked or COOP error - this should not happen with redirect flow");
2797
+ }
2798
+ alert("An error occurred during Microsoft login. Please try again.");
2636
2799
  }));
2637
2800
  } catch (e) {
2638
2801
  return Promise.reject(e);
@@ -4146,11 +4309,17 @@ exports.api = api;
4146
4309
  exports.apiUpload = apiUpload;
4147
4310
  exports.firstCheckToken = firstCheckToken;
4148
4311
  exports.getAccessToken = getAccessToken;
4312
+ exports.getActiveAccount = getActiveAccount;
4313
+ exports.getAllAccounts = getAllAccounts;
4149
4314
  exports.getErrorMessage = getErrorMessage;
4150
4315
  exports.getImageUrl = getImageUrl;
4316
+ exports.getMSALInstance = getMSALInstance;
4317
+ exports.handleMSALRedirect = handleMSALRedirect;
4151
4318
  exports.historyCore = historyCore;
4152
4319
  exports.initSentry = initSentry;
4153
4320
  exports.initializeAmplitude = initializeAmplitude;
4321
+ exports.initializeMSAL = initializeMSAL;
4322
+ exports.isMSALRedirect = isMSALRedirect;
4154
4323
  exports.setAddTenant = setAddTenant;
4155
4324
  exports.setAlert = setAlert;
4156
4325
  exports.setIsRefetchSidebar = setIsRefetchSidebar;