Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 93 Rev 96
Línea 1... Línea -...
1
import { axios } from "../../utils";
-
 
2
import { addNotification } from "../notification/notification.actions";
-
 
3
import { actionsTypes } from "./auth.types";
1
import { actionsTypes } from "./auth.types";
Línea 4... Línea -...
4
 
-
 
5
export const validateAuth = () => {
-
 
6
  return (dispatch) => {
-
 
7
    dispatch(startLoading());
-
 
8
 
-
 
9
    axios
-
 
10
      .get("/signin", { headers: { "Content-Type": "application/json" } })
-
 
11
      .then((response) => {
-
 
12
        const { success, data, fatal } = response.data;
-
 
13
 
-
 
14
        if (fatal) {
-
 
15
          dispatch(startLogout());
-
 
16
          return;
-
 
17
        }
-
 
18
 
-
 
19
        if (!success) {
-
 
20
          dispatch(addNotification({ style: "danger", msg: data }));
-
 
21
          return;
-
 
22
        }
-
 
23
 
-
 
24
        if (data.is_logged_in) {
-
 
25
          dispatch(login());
-
 
26
        } else {
-
 
27
          dispatch(startLogout());
-
 
28
        }
-
 
29
 
-
 
30
        if (data.jwt) {
-
 
31
          window.localStorage.setItem("jwt", data.jwt);
-
 
32
        }
-
 
33
 
-
 
34
        dispatch(setPermissions(data));
-
 
35
      })
-
 
36
      .catch((err) => {
-
 
37
        console.log(err);
-
 
38
        throw new Error(err);
-
 
39
      })
-
 
40
      .finally(() => dispatch(stopLoading()));
-
 
41
  };
-
 
42
};
-
 
43
 
2
 
44
const setPermissions = (permissions) => ({
3
export const setPermissions = (permissions) => ({
45
  type: actionsTypes.SET_PERMISSIONS,
4
  type: actionsTypes.SET_PERMISSIONS,
46
  payload: permissions,
5
  payload: permissions,
Línea 47... Línea 6...
47
});
6
});
Línea 56... Línea 15...
56
 
15
 
57
export const login = () => ({
16
export const login = () => ({
58
  type: actionsTypes.LOGIN,
17
  type: actionsTypes.LOGIN,
Línea 59... Línea -...
59
});
-
 
60
 
-
 
61
const startLogout = () => {
-
 
62
  return (dispatch) => {
-
 
63
    window.localStorage.removeItem("jwt");
-
 
64
    dispatch(logout());
-
 
65
  };
-
 
66
};
18
});
67
 
19
 
68
export const logout = () => ({
20
export const logout = () => ({