Created
November 9, 2020 06:25
-
-
Save blogcacanid/9759347d6b8de44ba9ccc4acfba47445 to your computer and use it in GitHub Desktop.
auth.service.js Authentication JWT Vue Lumen 7
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
import axios from 'axios'; | |
// for Lumen 7 back-end | |
const API_URL = 'http://localhost:8000/api/auth/'; | |
// for Node.js back-end | |
// const API_URL = 'http://localhost:9090/api/auth/'; | |
class AuthService { | |
login(user) { | |
return axios | |
.post(API_URL + 'login', { | |
username: user.username, | |
password: user.password | |
}) | |
.then(response => { | |
if (response.data.accessToken) { | |
localStorage.setItem('user', JSON.stringify(response.data)); | |
} | |
return response.data; | |
}); | |
} | |
logout() { | |
localStorage.removeItem('user'); | |
} | |
register(user) { | |
return axios.post(API_URL + 'register', { | |
username: user.username, | |
email: user.email, | |
password: user.password | |
}); | |
} | |
} | |
export default new AuthService(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment