| 3719 |
stevensc |
1 |
import { axios, isAndroidDevice, isIOSDevice, loginUserToNative, logoutUserToNative } from '@utils';
|
|
|
2 |
import { actionsTypes } from './auth.types';
|
|
|
3 |
|
|
|
4 |
export const setCrendentials = (crendentials) => ({
|
|
|
5 |
type: actionsTypes.SET_CREDENTIALS,
|
|
|
6 |
payload: crendentials
|
|
|
7 |
});
|
|
|
8 |
|
|
|
9 |
export const startLoading = () => ({
|
|
|
10 |
type: actionsTypes.START_LOADING
|
|
|
11 |
});
|
|
|
12 |
|
|
|
13 |
export const stopLoading = () => ({
|
|
|
14 |
type: actionsTypes.STOP_LOADING
|
|
|
15 |
});
|
|
|
16 |
|
|
|
17 |
export const asyncLogout = () => {
|
|
|
18 |
return async (dispatch) => {
|
|
|
19 |
const response = await axios.get('/signout');
|
|
|
20 |
|
|
|
21 |
const { success, data } = response.data;
|
|
|
22 |
const isAndroid = isAndroidDevice();
|
|
|
23 |
const isIOS = isIOSDevice();
|
|
|
24 |
|
|
|
25 |
if (!success) {
|
|
|
26 |
throw new Error('Error al cerrar sesión');
|
|
|
27 |
}
|
|
|
28 |
if (isAndroid || isIOS) logoutUserToNative(data.uuid);
|
|
|
29 |
|
|
|
30 |
window.localStorage.removeItem('jwt');
|
|
|
31 |
dispatch(logout());
|
|
|
32 |
|
|
|
33 |
return data;
|
|
|
34 |
};
|
|
|
35 |
};
|
|
|
36 |
|
|
|
37 |
export const asyncLogin = (formData) => {
|
|
|
38 |
return async (dispatch) => {
|
| 3736 |
stevensc |
39 |
const response = await axios.post('/signin/debug', formData);
|
| 3719 |
stevensc |
40 |
|
|
|
41 |
const { success, data } = response.data;
|
|
|
42 |
const isAndroid = isAndroidDevice();
|
|
|
43 |
const isIOS = isIOSDevice();
|
|
|
44 |
|
|
|
45 |
if (!success) {
|
|
|
46 |
throw new Error('Error al iniciar sesión');
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
if (isAndroid || isIOS) loginUserToNative(data.uuid);
|
|
|
50 |
|
|
|
51 |
dispatch(login());
|
|
|
52 |
|
|
|
53 |
const redirectPath = new URL(data.redirect).pathname;
|
|
|
54 |
return { ...data, redirect: redirectPath };
|
|
|
55 |
};
|
|
|
56 |
};
|
|
|
57 |
|
|
|
58 |
export const login = () => ({
|
|
|
59 |
type: actionsTypes.LOGIN
|
|
|
60 |
});
|
|
|
61 |
|
|
|
62 |
export const logout = () => ({
|
|
|
63 |
type: actionsTypes.LOGOUT
|
|
|
64 |
});
|