re-setup subproject kontor-vue
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
export default function authHeader() {
|
||||
let user = JSON.parse(localStorage.getItem("user"));
|
||||
|
||||
if (user && user.accessToken) {
|
||||
return { Authorization: "Bearer " + user.accessToken };
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = "http://localhost:8200/";
|
||||
|
||||
class AuthService {
|
||||
login(user) {
|
||||
return axios
|
||||
.post(API_URL + "login", {
|
||||
email: 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 + "signup", {
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
password: user.password,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new AuthService();
|
||||
@@ -0,0 +1,24 @@
|
||||
import axios from "axios";
|
||||
import authHeader from "./auth-header";
|
||||
|
||||
const API_URL = "http://localhost:8200/health/";
|
||||
|
||||
class UserService {
|
||||
getPublicContent() {
|
||||
return axios.get(API_URL + "all");
|
||||
}
|
||||
|
||||
getUserBoard() {
|
||||
return axios.get(API_URL + "user", { headers: authHeader() });
|
||||
}
|
||||
|
||||
getModeratorBoard() {
|
||||
return axios.get(API_URL + "mod", { headers: authHeader() });
|
||||
}
|
||||
|
||||
getAdminBoard() {
|
||||
return axios.get(API_URL + "admin", { headers: authHeader() });
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserService();
|
||||
Reference in New Issue
Block a user