Skip to content

How can i set guards for all my routes? How are the best practicies? #14067

Discussion options

You must be logged in to vote

move the guard to a boot:

https://github.com/TobyMosque/ws-auth-samples-frontend/blob/persist-after/src/boot/guard.ts#L6

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

export default boot(({ store, router }) => {
  // pass the pinia intance to your store is VERY IMPORTANT
  const authStore = useAuthStore(store)
  router.beforeEach((to) => {
    if (!authStore.isLoggedIn && to.name !== "Login") {
      return { name: "Login" }
    }
  })
});

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@wilsntn
Comment options

@adgower
Comment options

@adgower
Comment options

Answer selected by wilsntn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants