Skip to content

Instantly share code, notes, and snippets.

@tobyl
Created August 25, 2016 23:06
Show Gist options
  • Save tobyl/0caeeeaea535b90ba043bd0c73df0311 to your computer and use it in GitHub Desktop.
Save tobyl/0caeeeaea535b90ba043bd0c73df0311 to your computer and use it in GitHub Desktop.
const auth = {
login(payload) {
const email = payload.get('email');
const password = payload.get('password');
return fetch('/api/auth/jwt/token/', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
password,
}),
})
.then(response => response.json())
// .then(json => console.log(json))
.catch(err => console.log(err));
},
getAuthToken() {
console.log('%c ** auth -> getAuthToken() **', 'color: green;');
return localStorage.getItem('token');
},
setAuthToken(token) {
console.log('%c ** auth -> setAuthToken() **', 'color: green;');
localStorage.setItem('token', token);
},
removeAuthToken() {
console.log('%c ** auth -> removeAuthToken() **', 'color: green;');
localStorage.removeItem('token');
},
authSuccess() {
console.log('%c ** auth -> authSuccess() **', 'color: green;');
},
};
export default auth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment