allows 2 components in router guard

Viewed 22

i have this router guard which just open the sign in component if the user is not logged in how can i allow also the user to go to create account if he is not logged in . thanks in advance

import { LocalStorage } from "quasar";

export default ({ router }) => {
router.beforeEach((to, from, next) => {
let loggedIn = LocalStorage.getItem("loggedIn");
if (!loggedIn && to.path !== "/signin") {
  next("/signin");
} else {
  next();
}

}); };

1 Answers

If the user is not logged in and clicks on signup button then the user will be navigate to sign up path If the user is not logged in but tries to access any other routes other than signup, then the user redirects to signin

import { LocalStorage } from "quasar";

export default ({ router }) => {
router.beforeEach((to, from, next) => {
let loggedIn = LocalStorage.getItem("loggedIn");
if (!loggedIn && to.path === "/signup") {  // replace your signup path 
  next("/signup");
else if (!loggedIn && to.path !== "/signin") {
  next("/signin");
} else {
  next();
}
}); };
Related