Skip to content

Instantly share code, notes, and snippets.

@YKalashnikov
Last active July 4, 2019 01:01
Show Gist options
  • Save YKalashnikov/e2f4a985604f5a66cd20803170bd0a0c to your computer and use it in GitHub Desktop.
Save YKalashnikov/e2f4a985604f5a66cd20803170bd0a0c to your computer and use it in GitHub Desktop.
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