You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

83 lines
3.0 KiB

  1. import * as React from "react";
  2. import * as HttpUtils from "utils/HttpUtils";
  3. import * as UrlUtils from "utils/ApiPathConst";
  4. import { useNavigate } from "react-router-dom";
  5. import { useDispatch } from "react-redux";
  6. import { handleLogoutFunction, handleLogin } from 'auth/index';
  7. import Loadable from 'components/Loadable';
  8. const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent')));
  9. import {
  10. Grid,
  11. } from '@mui/material';
  12. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  13. const Index = () => {
  14. const dispatch = useDispatch()
  15. const navigate = useNavigate()
  16. React.useEffect(() => {
  17. goLogin();
  18. }, []);
  19. function goLogin(){
  20. dispatch(handleLogoutFunction());
  21. let params = new URLSearchParams(window.location.search)
  22. if(params.get("code")){
  23. HttpUtils.post({
  24. url: UrlUtils.GET_SMART_DIRECT_LOGIN,
  25. params:{
  26. code: params.get("code")
  27. },
  28. onSuccess: (responseData) => {
  29. console.log("responseData");
  30. console.log(responseData);
  31. const userData = {
  32. id: responseData.id,
  33. fullenName: responseData.name,
  34. fullchName: responseData.chName,
  35. email: responseData.email,
  36. type: responseData.type,
  37. role: responseData.role,
  38. abilities: responseData.abilities,
  39. creditor: responseData.creditor,
  40. //avatar: require('src/assets/images/users/avatar-3.png').default,
  41. }
  42. const data = { ...userData, accessToken: responseData.accessToken, refreshToken: responseData.refreshToken }
  43. dispatch(handleLogin(data))
  44. navigate('/dashboard');
  45. },
  46. onFail: (response)=>{
  47. console.log("Fail");
  48. console.log(response);
  49. window.location.assign("/iamsmart/loginFail");
  50. },
  51. onError:(error)=>{
  52. console.log("onError");
  53. console.log(error);
  54. if(error?.response?.data?.exception == "msg: please verify email."){
  55. window.location.assign("/iamsmart/notverify");
  56. }else{
  57. window.location.assign("/iamsmart/loginFail");
  58. }
  59. }
  60. });
  61. }else{
  62. window.location.assign("/iamsmart/loginFail");
  63. }
  64. }
  65. return (
  66. <Grid container sx={{ minHeight: '87vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  67. <Grid item>
  68. <LoadingComponent />
  69. </Grid>
  70. </Grid>
  71. );
  72. };
  73. export default Index;