Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 66 Rev 71
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
const getPermissions = () => {
4
export const validateAuth = () => {
-
 
5
  return (dispatch) => {
-
 
6
    dispatch(startLoading());
5
  return (dispatch) => {
7
 
6
    axios
8
    axios
7
      .get("/signin", { headers: { "Content-Type": "application/json" } })
9
      .get("/signin", { headers: { "Content-Type": "application/json" } })
8
      .then((response) => {
10
      .then((response) => {
Línea 14... Línea 16...
14
 
16
 
15
        if (data.jwt) {
17
        if (data.jwt) {
16
          window.localStorage.setItem("jwt", data.jwt);
18
          window.localStorage.setItem("jwt", data.jwt);
Línea -... Línea 19...
-
 
19
        }
-
 
20
 
-
 
21
        if (data.is_logged_in) {
-
 
22
          dispatch(login());
-
 
23
        } else {
-
 
24
          dispatch(startLogout());
17
        }
25
        }
18
 
26
 
19
        dispatch(setPermissions(data));
27
        dispatch(setPermissions(data));
20
      })
28
      })
21
      .catch((err) => {
29
      .catch((err) => {
22
        console.log(err);
30
        console.log(err);
23
        throw new Error(err);
31
        throw new Error(err);
24
      })
32
      })
25
      .finally(() => dispatch(stopLoading()));
33
      .finally(() => dispatch(stopLoading()));
Línea 26... Línea -...
26
  };
-
 
27
};
-
 
28
 
-
 
29
export const validateAuth = () => {
-
 
30
  return (dispatch) => {
-
 
31
    dispatch(startLoading());
-
 
32
 
-
 
33
    const token = window.localStorage.getItem("jwt");
-
 
34
 
-
 
35
    if (token) {
-
 
36
      dispatch(login());
-
 
37
      dispatch(stopLoading());
-
 
38
    } else {
-
 
39
      dispatch(getPermissions());
-
 
40
    }
-
 
41
  };
34
  };
42
};
35
};
43
 
36
 
44
const setPermissions = (permissions) => ({
37
const setPermissions = (permissions) => ({
Línea 56... Línea 49...
56
 
49
 
57
export const login = () => ({
50
export const login = () => ({
58
  type: actionsTypes.LOGIN,
51
  type: actionsTypes.LOGIN,
Línea -... Línea 52...
-
 
52
});
-
 
53
 
-
 
54
const startLogout = () => {
-
 
55
  return (dispatch) => {
-
 
56
    window.localStorage.removeItem("jwt");
-
 
57
    dispatch(logout());
-
 
58
  };
59
});
59
};
60
 
60
 
61
export const logout = () => ({
61
export const logout = () => ({