|
@@ -1,6 +1,5 @@
|
|
-import {gqlLogin, gqlRegistration} from "../../shared/services&utilits/gqlRequest";
|
|
|
|
|
|
+import {actionAboutMe, gqlLogin, gqlRegistration} from "../../shared/services&utilits/gqlRequest";
|
|
import {jwtDecode} from "../../shared/services&utilits/utilits";
|
|
import {jwtDecode} from "../../shared/services&utilits/utilits";
|
|
-import {Link} from "react-router-dom";
|
|
|
|
|
|
|
|
export const changeAuthData = authData => ({
|
|
export const changeAuthData = authData => ({
|
|
type: "CHANGE_AUTH_DATA",
|
|
type: "CHANGE_AUTH_DATA",
|
|
@@ -13,11 +12,9 @@ export const setError = error => ({
|
|
})
|
|
})
|
|
|
|
|
|
export const changeAuthDataAsync = ({login, password, authType, navigateCallback}) => {
|
|
export const changeAuthDataAsync = ({login, password, authType, navigateCallback}) => {
|
|
- console.log(navigateCallback)
|
|
|
|
return async (dispatch) => {
|
|
return async (dispatch) => {
|
|
let response = ""
|
|
let response = ""
|
|
if (authType === "signUp") {
|
|
if (authType === "signUp") {
|
|
- console.log("Регистрация")
|
|
|
|
response = await gqlRegistration(login, password)
|
|
response = await gqlRegistration(login, password)
|
|
if (!response.ok) {
|
|
if (!response.ok) {
|
|
dispatch(setError("Server is not answer"))
|
|
dispatch(setError("Server is not answer"))
|
|
@@ -26,17 +23,16 @@ export const changeAuthDataAsync = ({login, password, authType, navigateCallback
|
|
const responseData = await response.json();
|
|
const responseData = await response.json();
|
|
console.log(responseData)
|
|
console.log(responseData)
|
|
const user = responseData.data.createUser;
|
|
const user = responseData.data.createUser;
|
|
-
|
|
|
|
|
|
+ console.log(user)
|
|
if (user) {
|
|
if (user) {
|
|
dispatch(changeAuthDataAsync({login, password, authType: "signIn", navigateCallback}))
|
|
dispatch(changeAuthDataAsync({login, password, authType: "signIn", navigateCallback}))
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
dispatch(setError("Login is already exist"))
|
|
dispatch(setError("Login is already exist"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (authType === "signIn") {
|
|
if (authType === "signIn") {
|
|
- console.log(login,password)
|
|
|
|
response = await gqlLogin(login, password)
|
|
response = await gqlLogin(login, password)
|
|
- console.log(response)
|
|
|
|
if (!response.ok) {
|
|
if (!response.ok) {
|
|
dispatch(setError("Server is not answer"))
|
|
dispatch(setError("Server is not answer"))
|
|
}
|
|
}
|
|
@@ -47,20 +43,33 @@ export const changeAuthDataAsync = ({login, password, authType, navigateCallback
|
|
if (jwtDecode(token)){
|
|
if (jwtDecode(token)){
|
|
localStorage.authToken = token
|
|
localStorage.authToken = token
|
|
}
|
|
}
|
|
- // console.log(jwtDecode(token))
|
|
|
|
-
|
|
|
|
|
|
|
|
if (!token) {
|
|
if (!token) {
|
|
dispatch(setError("Wrong login or password"))
|
|
dispatch(setError("Wrong login or password"))
|
|
} else {
|
|
} else {
|
|
dispatch(changeAuthData({token: token, user: jwtDecode(token)}))
|
|
dispatch(changeAuthData({token: token, user: jwtDecode(token)}))
|
|
dispatch(setError(null))
|
|
dispatch(setError(null))
|
|
- console.log(navigateCallback)
|
|
|
|
navigateCallback("../profile")
|
|
navigateCallback("../profile")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (authType === "ownerData") {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+export const setActiveUserDataAsync = (id) => {
|
|
|
|
+ return async (dispatch) => {
|
|
|
|
+ let response = ""
|
|
|
|
+
|
|
|
|
+ response = await actionAboutMe(id)
|
|
|
|
+
|
|
|
|
+ if (!response.ok) {
|
|
|
|
+ dispatch(setError("No user data received"))
|
|
|
|
+ }
|
|
|
|
+ const responseData = await response.json();
|
|
|
|
+ console.log(responseData)
|
|
|
|
+ dispatch(setActiveUserData(responseData.data.UserFindOne))
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+export const setActiveUserData =(data)=>({
|
|
|
|
+ type: "SET_ACTIVE_USER_DATA",
|
|
|
|
+ payload: data,
|
|
|
|
+} )
|