mint_beach_vue
Version:
A VueJS 3 plugin used to extend the mint_beach_js library. This plugin will add mint_beach_js functions to the vue global properties. It will expose a global getCurrentUser() method and keep track of the current user's access token in local storage.
38 lines (32 loc) • 1.1 kB
JavaScript
import { mb, mb_admin, init } from "mint_beach_js";
import initAuth from "./auth.js";
import cart from "./cart.plugin.js";
export default {
install(Vue, options) {
//Initialize base URL for API
init(options.baseURL);
const { currentUser, checkAuth, login, logout, signup } = initAuth(options);
//Add $mb and $mb_admin to Vue's gobal properties
Vue.config.globalProperties.$mb = mb(options.tenantId, options.tenantId);
Vue.config.globalProperties.$mb.auth.login = login;
Vue.config.globalProperties.$mb.auth.logout = logout;
Vue.config.globalProperties.$mb.auth.signup = signup;
Vue.config.globalProperties.$mb.auth.getCurrentUser = () => currentUser;
Vue.config.globalProperties.$mb_admin = mb_admin;
//Define a vue mixin that will be added to the root vue instance
Vue.mixin({
data() {
return {
currentUser: this.$mb.auth.getCurrentUser(),
};
},
methods: {
async loadCurrentUser() {
await checkAuth();
},
},
});
//Use cart plugin
Vue.use(cart);
},
};