Skip to content

Instantly share code, notes, and snippets.

@blogcacanid
Created November 9, 2020 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogcacanid/9759347d6b8de44ba9ccc4acfba47445 to your computer and use it in GitHub Desktop.
Save blogcacanid/9759347d6b8de44ba9ccc4acfba47445 to your computer and use it in GitHub Desktop.
auth.service.js Authentication JWT Vue Lumen 7
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