12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { actionPromise } from "./actionsPromise";
- import { gql } from "../helpers/gql";
- import { history } from '../App';
- import { actionAboutMe } from "./actionAboutMe";
- export const socket = window.io("ws://chat.ed.asmer.org.ua/")
- const actionAuthLogin = (token) => ({type: 'AUTH_LOGIN', token});
- export const actionAuthLogout = () => {
- history.push('/')
- return ({type: 'AUTH_LOGOUT'})
- }
- export const actionFullLogin = (log, pass) =>
- async (dispatch) => {
- let token = await dispatch(
- actionPromise('login', gql(`query login($login: String, $password: String) {
- login(login: $login, password: $password)
- }`, {login: log, password: pass}))
- )
- if(token){
- socket.emit('jwt', token)
- dispatch(actionAuthLogin(token))
- history.push("/");
-
- }
- return token
- }
- export const actionCheckPassword = (log, pass) =>
- async (dispatch) => {
- let token = await dispatch(
- actionPromise('checkedPassword', gql(`query login($login: String, $password: String) {
- login(login: $login, password: $password)
- }`, {login: log, password: pass}))
- );
- console.log(token)
- }
- export const actionFullRegister = (log, pass, nick) =>
- async dispatch => {
- let user = await dispatch(
- actionPromise('register', gql( `mutation register($user: UserInput) {
- UserUpsert(user: $user) {
- _id
- login
- }
- }`, {
- user: {
- login: log,
- password: pass,
- nick: nick
- }
- }))
- )
- if(user){
- dispatch(actionFullLogin(log, pass));
- }
- }
|