acsi-core 1.2.30 → 1.2.32

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.
@@ -1,5 +1,5 @@
1
- export declare const getGoogleClientId: () => Promise<import("axios").AxiosResponse<any, any>>;
2
- export declare const apiLoginGoogle: (body: any) => Promise<import("axios").AxiosResponse<any, any>>;
3
- export declare const apiSendEmailCode: (body: any) => Promise<import("axios").AxiosResponse<any, any>>;
4
- export declare const apiCheckEmailCode: (params: any) => Promise<import("axios").AxiosResponse<any, any>>;
5
- export declare const apiGetImage: () => Promise<import("axios").AxiosResponse<any, any>>;
1
+ export declare const getGoogleClientId: () => Promise<import("axios").AxiosResponse<any, any, {}>>;
2
+ export declare const apiLoginGoogle: (body: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
3
+ export declare const apiSendEmailCode: (body: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
4
+ export declare const apiCheckEmailCode: (params: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
5
+ export declare const apiGetImage: () => Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -5,7 +5,7 @@ declare type LoginInfo = {
5
5
  captcha: string;
6
6
  rememberMe: boolean;
7
7
  };
8
- declare const useLogin: (onNavigate: any, trackEvent?: ((props: any) => void) | undefined) => {
8
+ declare const useLogin: (_onNavigate: any, trackEvent?: ((props: any) => void) | undefined) => {
9
9
  defaultInfo: LoginInfo;
10
10
  openLogin: boolean;
11
11
  toggle: () => void;
package/dist/index.js CHANGED
@@ -1838,8 +1838,8 @@ var msalConfig = function msalConfig(clientId, redirectUri) {
1838
1838
  };
1839
1839
 
1840
1840
  var BlockLogin = function BlockLogin(_ref) {
1841
- var onNavigate = _ref.onNavigate,
1842
- role = _ref.role,
1841
+ var _ref$role = _ref.role,
1842
+ role = _ref$role === void 0 ? "LandingPage" : _ref$role,
1843
1843
  hiddenSignup = _ref.hiddenSignup,
1844
1844
  email = _ref.email,
1845
1845
  setEmail = _ref.setEmail,
@@ -1919,7 +1919,7 @@ var BlockLogin = function BlockLogin(_ref) {
1919
1919
  };
1920
1920
  dispatch(setLoading(true));
1921
1921
  return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
1922
- var _authResult$data;
1922
+ var _authResult$data, _authResult$data2, _authResult$data2$rol, _authResult$data3;
1923
1923
  if (((_authResult$data = authResult.data) === null || _authResult$data === void 0 ? void 0 : _authResult$data.id) == null) {
1924
1924
  dispatch(setLoading(false));
1925
1925
  alert("Please contact admin.");
@@ -1937,27 +1937,16 @@ var BlockLogin = function BlockLogin(_ref) {
1937
1937
  timestamp: new Date().toISOString()
1938
1938
  }
1939
1939
  });
1940
- if (role === "LandingPage") {
1941
- CookieService.setAuthCookie({
1942
- token: tokenJWT,
1943
- expiresAt: Date.now() + 24 * 60 * 60 * 1000
1944
- });
1945
- var getRedirectUrl = function getRedirectUrl(role) {
1946
- switch (role) {
1947
- case "Admin":
1948
- return ADMIN_ORIGIN;
1949
- case "Teacher":
1950
- return TEACHER_ORIGIN;
1951
- default:
1952
- return role + "." + REQUEST_ORIGIN;
1953
- }
1954
- };
1955
- var redirectUrl = getRedirectUrl(authResult.data.role);
1956
- window.location.href = redirectUrl + "/dashboard";
1957
- dispatch(setLoading(false));
1958
- }
1940
+ CookieService.setAuthCookie({
1941
+ token: tokenJWT,
1942
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
1943
+ });
1959
1944
  localStorage.setItem(ACCESS_TOKEN, tokenJWT);
1960
- onNavigate("/dashboard");
1945
+ var domain = "/teacher";
1946
+ if ((_authResult$data2 = authResult.data) !== null && _authResult$data2 !== void 0 && (_authResult$data2$rol = _authResult$data2.roles) !== null && _authResult$data2$rol !== void 0 && _authResult$data2$rol.includes("Admin") || ((_authResult$data3 = authResult.data) === null || _authResult$data3 === void 0 ? void 0 : _authResult$data3.role) === "Admin") {
1947
+ domain = "/admin";
1948
+ }
1949
+ window.location.href = domain + "/dashboard";
1961
1950
  dispatch(setLoading(false));
1962
1951
  });
1963
1952
  }
@@ -2006,8 +1995,8 @@ var BlockLogin = function BlockLogin(_ref) {
2006
1995
  };
2007
1996
  dispatch(setLoading(true));
2008
1997
  return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2009
- var _authResult$data2;
2010
- if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
1998
+ var _authResult$data4, _authResult$data5, _authResult$data5$rol, _authResult$data6;
1999
+ if (((_authResult$data4 = authResult.data) === null || _authResult$data4 === void 0 ? void 0 : _authResult$data4.id) == null) {
2011
2000
  dispatch(setLoading(false));
2012
2001
  alert("Please contact admin.");
2013
2002
  return;
@@ -2024,27 +2013,16 @@ var BlockLogin = function BlockLogin(_ref) {
2024
2013
  timestamp: new Date().toISOString()
2025
2014
  }
2026
2015
  });
2027
- if (role === "LandingPage") {
2028
- CookieService.setAuthCookie({
2029
- token: tokenJWT,
2030
- expiresAt: Date.now() + 24 * 60 * 60 * 1000
2031
- });
2032
- var getRedirectUrl = function getRedirectUrl(role) {
2033
- switch (role) {
2034
- case "Admin":
2035
- return ADMIN_ORIGIN;
2036
- case "Teacher":
2037
- return TEACHER_ORIGIN;
2038
- default:
2039
- return role + "." + REQUEST_ORIGIN;
2040
- }
2041
- };
2042
- var redirectUrl = getRedirectUrl(authResult.data.role);
2043
- window.location.href = redirectUrl + "/dashboard";
2044
- dispatch(setLoading(false));
2045
- }
2016
+ CookieService.setAuthCookie({
2017
+ token: tokenJWT,
2018
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
2019
+ });
2046
2020
  localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2047
- onNavigate("/dashboard");
2021
+ var domain = "/teacher";
2022
+ if ((_authResult$data5 = authResult.data) !== null && _authResult$data5 !== void 0 && (_authResult$data5$rol = _authResult$data5.roles) !== null && _authResult$data5$rol !== void 0 && _authResult$data5$rol.includes("Admin") || ((_authResult$data6 = authResult.data) === null || _authResult$data6 === void 0 ? void 0 : _authResult$data6.role) === "Admin") {
2023
+ domain = "/admin";
2024
+ }
2025
+ window.location.href = domain + "/dashboard";
2048
2026
  dispatch(setLoading(false));
2049
2027
  });
2050
2028
  }
@@ -2420,7 +2398,7 @@ var defaultInfo = {
2420
2398
  rememberMe: false
2421
2399
  };
2422
2400
  var minutes = 15;
2423
- var useLogin = function useLogin(onNavigate, trackEvent) {
2401
+ var useLogin = function useLogin(_onNavigate, trackEvent) {
2424
2402
  var _useState = React.useState(false),
2425
2403
  openLogin = _useState[0],
2426
2404
  setOpenLogin = _useState[1];
@@ -2487,6 +2465,7 @@ var useLogin = function useLogin(onNavigate, trackEvent) {
2487
2465
  })).then(function (res) {
2488
2466
  var data = res.data;
2489
2467
  if (data.success) {
2468
+ var _data$data$roles;
2490
2469
  localStorage.clear();
2491
2470
  var tokenJWT = data.data.token;
2492
2471
  localStorage.setItem(ACCESS_TOKEN, tokenJWT);
@@ -2498,21 +2477,15 @@ var useLogin = function useLogin(onNavigate, trackEvent) {
2498
2477
  timestamp: new Date().toISOString()
2499
2478
  }
2500
2479
  });
2501
- var isRootDomain = window.location.hostname === REQUEST_ORIGIN || window.location.hostname === "www." + REQUEST_ORIGIN;
2502
- if (isRootDomain) {
2503
- var _data$data$roles;
2504
- CookieService.setAuthCookie({
2505
- token: tokenJWT,
2506
- expiresAt: Date.now() + 24 * 60 * 60 * 1000
2507
- });
2508
- var domain = TEACHER_ORIGIN;
2509
- if ((_data$data$roles = data.data.roles) !== null && _data$data$roles !== void 0 && _data$data$roles.includes("Admin")) {
2510
- domain = ADMIN_ORIGIN;
2511
- }
2512
- window.location.href = domain + "/dashboard";
2513
- } else {
2514
- onNavigate("/dashboard");
2480
+ CookieService.setAuthCookie({
2481
+ token: tokenJWT,
2482
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
2483
+ });
2484
+ var domain = "/teacher";
2485
+ if ((_data$data$roles = data.data.roles) !== null && _data$data$roles !== void 0 && _data$data$roles.includes("Admin") || data.data.role === "Admin") {
2486
+ domain = "/admin";
2515
2487
  }
2488
+ window.location.href = domain + "/dashboard";
2516
2489
  } else {
2517
2490
  reactToastify.toast.error("The code is not correct. Please check again.");
2518
2491
  }