@@ -85,18 +85,27 @@ export default {
8585 };
8686 },
8787 created () {
88- // manual settings
89- this .$store .commit (' fm/settings/manualSettings' , this .settings );
90- // initiate Axios
91- this .$store .commit (' fm/settings/initAxiosSettings' );
92- this .setAxiosConfig ();
93- this .requestInterceptor ();
94- this .responseInterceptor ();
95-
96- // initialize app settings
97- // Mohammad Ashrafuddin Ferdousi : 1
98- // Mohammad Ashrafuddin Ferdousi : 2
99- this .$store .dispatch (' fm/initializeApp' );
88+ new Promise (resolve => {
89+ // manual settings
90+ this .$store .commit (' fm/settings/manualSettings' , this .settings );
91+ resolve ();
92+ }).then (() => {
93+ // initiate Axios
94+ this .$store .commit (' fm/settings/initAxiosSettings' );
95+ }).then (() => {
96+ this .setAxiosConfig ();
97+ }).then (() => {
98+ this .requestInterceptor ();
99+ }).then (() => {
100+ this .responseInterceptor ();
101+ }).then (() => {
102+ // initialize app settings
103+ // Mohammad Ashrafuddin Ferdousi : 1
104+ // Mohammad Ashrafuddin Ferdousi : 2
105+ this .$store .dispatch (' fm/initializeApp' );
106+ }).catch (err => {
107+ Promise .reject (err);
108+ });
100109 },
101110 destroyed () {
102111 // reset state
@@ -118,44 +127,19 @@ export default {
118127 }),
119128 },
120129 methods: {
121- storeAxiosConfig () {
122- localstore .setStorage (localstore .axiosSettingType , this .settings );
123- },
124130 /**
125131 * Axios default config
126132 */
127- setAxiosConfig () {
128- /** Original version **/
129- /* HTTP.defaults.baseURL = this.$store.getters['fm/settings/baseUrl'];
130- HTTP.defaults.headers = this.$store.getters['fm/settings/headers'];*/
131-
132- /** Customized by Mohammad Ashrafuddin Ferdousi */
133- // Uncomment when needed.
134- /* let settings = localstore.getStorage(localstore.axiosSettingType);
135-
136- if(settings) {
137- HTTP.interceptors.request.use(config => {
138- config.baseURL = settings.baseURL;
139- config.withCredentials = settings.withCredentials;
140- config.headers = settings.headers;
141- config.headers.common.Authorization = `Bearer ${window.localStorage.getItem('_token')}`;
142-
143- return config;
144- }, error => Promise.reject(error)
145- );
146- } else {
147- throw `settings.baseURL: ${settings.baseURL}, settings.withCredentials: ${settings.withCredentials}, settings.headers: ${settings.headers} is set!`;
148- }*/
149- // End of uncomment when needed.
150- HTTP .interceptors .request .use (config => {
151- config .baseURL = this .$store .getters [' fm/settings/baseUrl' ];
152- config .withCredentials = this .$store .getters [' fm/settings/withCredentials' ];
153- config .headers = this .$store .getters [' fm/settings/headers' ];
154- config .headers .common .Authorization = ` Bearer ${ window .localStorage .getItem (' _token' )} ` ;
155-
156- return config;
157- }, error => Promise .reject (error)
158- );
133+ async setAxiosConfig () {
134+ HTTP .defaults .baseURL = this .$store .getters [' fm/settings/baseUrl' ];
135+ HTTP .defaults .withCredentials = this .$store .getters [' fm/settings/withCredentials' ];
136+ HTTP .defaults .headers = this .$store .getters [' fm/settings/headers' ];
137+ HTTP .defaults .headers .common = {};
138+ HTTP .defaults .headers .common [' X-Requested-With' ] = ' XMLHttpRequest' ;
139+ let token = await new Promise (resolve => {
140+ resolve (window .localStorage .getItem (' _token' ));
141+ });
142+ HTTP .defaults .headers .Authorization = ` Bearer ${ token} ` ;
159143 },
160144
161145 /**
0 commit comments