1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { actionIsLoading } from '../../loading/action';
- import {
- actionLogInSuccess,
- actionLogInReject,
- actionLogOutSuccess,
- actionLogOutReject,
- } from '../action';
- import { loginGQL, registerGQL } from '../../../api-data';
- const asyncLogin = (login, password) => async dispatch => {
- try {
- dispatch(actionIsLoading(true));
- const token = await loginGQL(login, password);
- console.log(token);
- dispatch(actionLogInSuccess({ login, token }));
- } catch (e) {
- dispatch(actionLogInReject());
- } finally {
- dispatch(actionIsLoading(false));
- }
- };
- const asyncLogout = () => async dispatch => {
- try {
- dispatch(actionIsLoading(true));
- dispatch(actionLogOutSuccess());
- } catch (e) {
- dispatch(actionLogOutReject());
- } finally {
- dispatch(actionIsLoading(false));
- }
- };
- const asyncCreateUser = (login, password) => async dispatch => {
- try {
- dispatch(actionIsLoading(true));
- await registerGQL(login, password);
- const token = await loginGQL(login, password);
- console.log(token);
- dispatch(actionLogInSuccess({ login, token }));
- } catch (e) {
- console.error('Credentials have already used', e);
- } finally {
- dispatch(actionIsLoading(false));
- }
- };
- export { asyncLogin, asyncLogout, asyncCreateUser };
|