Last active
July 4, 2019 01:01
-
-
Save YKalashnikov/e2f4a985604f5a66cd20803170bd0a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getProfileFetch = () => { | |
return dispatch => { | |
const token = localStorage.token; | |
if (token) { | |
return fetch("http://localhost:3000/api/v1/profile", { | |
method: "GET", | |
headers: { | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
'Authorization': `Bearer ${token}` | |
} | |
}) | |
.then(resp => resp.json()) | |
.then(data => { | |
if (data.message) { | |
// Будет ошибка если token не дествительный | |
localStorage.removeItem("token") | |
} else { | |
dispatch(loginUser(data.user)) | |
} | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment