Skip to content

Instantly share code, notes, and snippets.

@alur222
Last active April 2, 2019 06:55
Show Gist options
  • Save alur222/c9bbb3e1c061d294606e63b94498cd9c to your computer and use it in GitHub Desktop.
Save alur222/c9bbb3e1c061d294606e63b94498cd9c to your computer and use it in GitHub Desktop.
verfying token authenticity from localStorage
// replace LS_ITEM_NAME with your localstorage item name
// REACT_APP_BACKEND_HOST
// server should accept custom header "x-access-token"
export const AuthVerify = async () => {
const token = localStorage.getItem(LS_ITEM_NAME);
if (!token) {
return Promise.reject(false);
}
return axios.request({
method: 'post',
url: `${process.env.REACT_APP_BACKEND_HOST}/auth/verify`,
headers: {
'x-access-token': token,
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment