configuration for Axios and vue auth api

This commit is contained in:
2020-04-09 10:38:27 +02:00
parent ad70249daf
commit c7ea6c0b47
7 changed files with 70 additions and 4 deletions
+1 -1
View File
@@ -5,6 +5,6 @@ export default {
// get all applications
getAll()
{
return Axios.get(zero.path + 'api/applications/getAll').then(res => Promise.resolve(res.data));
return Axios.get('applications/getAll').then(res => Promise.resolve(res.data));
}
};
+1 -1
View File
@@ -5,7 +5,7 @@ export default {
// get all pages with a certain parent (can be empty)
getChildren(parent)
{
return Axios.get(zero.path + 'api/pageTree/getChildren', {
return Axios.get('pageTree/getChildren', {
params: {
parent: parent
}
+1 -1
View File
@@ -5,6 +5,6 @@ export default {
// get all sections
getAll()
{
return Axios.get(zero.path + 'api/sections/getAll').then(res => Promise.resolve(res.data));
return Axios.get('sections/getAll').then(res => Promise.resolve(res.data));
}
};
+1 -1
View File
@@ -5,6 +5,6 @@ export default {
// get all settings areas
getAreas()
{
return Axios.get(zero.path + 'api/settings/getAreas').then(res => Promise.resolve(res.data));
return Axios.get('settings/getAreas').then(res => Promise.resolve(res.data));
}
};
+39
View File
@@ -0,0 +1,39 @@
import Vue from 'vue';
import Strings from 'zeroservices/strings';
import { find as _find, extend as _extend } from 'underscore';
export default new Vue({
data: () => ({
isAuthenticated: false,
user: null
}),
methods: {
// loads the current user into the cache
loadUser()
{
},
// the cached user has been rejected by the server so we clear credentials here
rejectUser()
{
this.isAuthenticated = false;
this.user = null;
},
// logs the user in with the passed credentials
login()
{
},
// logs the current user out
logout()
{
}
}
});
+1
View File
@@ -14,6 +14,7 @@
import AppNavigation from 'zero/navigation.vue'
import AppOverlays from 'zerocomponents/Overlays/overlay-holder.vue'
import Router from '../router.js'
import 'zero/axios.config.js'
export default {
name: 'app',
+26
View File
@@ -0,0 +1,26 @@
import Axios from 'axios';
import Auth from 'zeroservices/auth';
if (!zero || !zero.path)
{
throw Exception('window.zero and zero.path (= base path) have to be configured');
}
Axios.defaults.baseURL = zero.path + 'api/';
Axios.defaults.withCredentials = true;
Axios.interceptors.response.use(response => response, error =>
{
if (error.response)
{
if (error.response.status === 401)
{
Auth.rejectUser();
//Notification.error('Authentication failed. Please login again.', 3);
}
}
return Promise.reject(error);
});
export default Axios;