Skip to content
Discussion options

You must be logged in to vote

You can use a boot file where you have access to the router, to the store, and more.

import { boot } from 'quasar/wrappers';
import { useAuthStore } from 'stores/auth';

export default boot(({ router, store }) => {
  // the store parameter is optional for non-SSR apps
  const authStore = useAuthStore(store);

  router.beforeEach((to, from) => {
    if (authStore.user == null && to.path !== "/login" ) {
      return { path: "/login" }
    }

    if (authStore.user !== null && to.path === "/login") {
      return { path: "/" }
    }
  });
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yusufkandemir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants