I have 3 domains that users can choose when they log in. Let's say I have domains dev, demo, and sandbox. I use Axios in which the domain instance is configured in the Boot.js file. The boot file is only triggered when the Vue instance is still not fired. Here is the boot file:
import { boot } from "quasar/wrappers";
import axios from "axios";
import { LocalStorage } from "quasar";
import { Platform } from "quasar";
let baseURL = LocalStorage.getItem("basepath");
let api = axios.create({ baseURL: baseURL });
export default boot(({ app }) => {
// for use inside Vue files (Options API) through this.$axios and this.$api
app.config.globalProperties.$axios = axios;
// ^ ^ ^ this will allow you to use this.$axios (for Vue Options API form)
// so you won't necessarily have to import axios in each vue file
app.config.globalProperties.$api = api;
// ^ ^ ^ this will allow you to use this.$api (for Vue Options API form)
// so you can easily perform requests against your app's API
});
export { axios, api };
Here is the script chunk of the login file:
<script>
import { LocalStorage } from "quasar";
export default {
data() {
return {
companyList: [{
id: "dev",
site: "https://dev.mycompany.com",
},
{
id: "demo",
site: "https://demo.mycompany.com",
},
{
id: "sandbox",
site: "https://sandbox.mycompany.com",
},
],
loginData: {
username: "",
password: "",
companyid: "",
},
};
},
methods: {
checkCompanyId(payload) {
let temp = this.companyList.find((o) => o.id == payload.toLowerCase());
if (temp) {
LocalStorage.set("basepath", temp.site); // <-- Here is the setting of the basepath
return true;
} else {
return false;
}
},
submitForm() {
const CompanyId = this.checkCompanyId(this.loginData.companyid);
if (CompanyId) {
this.loginProcess(this.loginData);
} else {
console.log('Company ID can't be found!')
}
}
},
}
}
</script>
The problem is the Local Storage is actually changed but the variable baseURL in the Boot.js file is not changed unless I reload the page. Is there possibly a way to reassign the variable baseURL whenever the local storage has changed?