Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 38 | Rev 64 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 38 Rev 63
Línea 1... Línea 1...
1
import { axios } from "../../utils";
1
import { axios } from "../../utils";
2
import { actionsTypes } from "./auth.types";
2
import { actionsTypes } from "./auth.types";
Línea 3... Línea 3...
3
 
3
 
4
export const getPermissions = () => {
4
const getPermissions = () => {
5
  return (dispatch) => {
5
  return (dispatch) => {
6
    dispatch(startLoading());
6
    dispatch(startLoading());
7
    axios
7
    axios
8
      .get("/signin", { headers: { "Content-Type": "application/json" } })
8
      .get("/signin", { headers: { "Content-Type": "application/json" } })
9
      .then((response) => {
9
      .then((response) => {
Línea 10... Línea 10...
10
        const { success, data: permissions } = response.data;
10
        const { success, data } = response.data;
11
 
11
 
12
        if (permissions.jwt) {
12
        if (!success) {
Línea 13... Línea 13...
13
          window.localStorage.setItem("jwt", permissions.jwt);
13
          throw new Error(data);
14
        }
14
        }
15
 
15
 
-
 
16
        if (data.jwt) {
-
 
17
          window.localStorage.setItem("jwt", data.jwt);
16
        dispatch(
18
        }
17
          setPermissions({ ...permissions, isAuth: permissions.is_logged_in })
19
 
18
        );
20
        dispatch(setPermissions(data));
19
      })
21
      })
20
      .catch((err) => {
22
      .catch((err) => {
21
        console.log(err);
23
        console.log(err);
22
        throw new Error(err);
24
        throw new Error(err);
23
      })
25
      })
Línea -... Línea 26...
-
 
26
      .finally(() => dispatch(stopLoading()));
-
 
27
  };
-
 
28
};
-
 
29
 
-
 
30
export const validateAuth = () => {
-
 
31
  return (dispatch) => {
-
 
32
    const token = window.localStorage.getItem("jwt");
-
 
33
 
-
 
34
    if (token) {
-
 
35
      dispatch(login());
-
 
36
      return;
-
 
37
    }
-
 
38
 
24
      .finally(() => dispatch(stopLoading()));
39
    dispatch(getPermissions());
25
  };
40
  };
26
};
41
};
27
 
42