configuration for Axios and vue auth api
This commit is contained in:
@@ -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));
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user