We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Following the Vue Router docs on adding a route guard to prevent un-authenticated users from viewing any routes and get redirected to /login (https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards).
I tried the following index.js for the router component:
import { createRouter, createWebHistory } from 'vue-router' import HomeView from '../views/HomeView.vue' import {useAuth0} from "@auth0/auth0-vue"; const routes = [ { path: '/', name: 'home', component: HomeView }, { path: '/login', name: 'login', component: () => import(/* webpackChunkName: "about" */ '../views/LoginView.vue') } ] const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes }) router.beforeEach(async (to) => { const isAuthenticated = useAuth0().isAuthenticated; if (!isAuthenticated && to.name !== 'login') { return { name: 'login' } } }) export default router
The problem is useAuth0() is undefined, also when I do const { isAuthenticated } = useAuth0();.
undefined
const { isAuthenticated } = useAuth0();
Please add an example how to correctly do this.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Following the Vue Router docs on adding a route guard to prevent un-authenticated users from viewing any routes and get redirected to /login (https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards).
I tried the following index.js for the router component:
The problem is useAuth0() is
undefined
, also when I doconst { isAuthenticated } = useAuth0();
.Please add an example how to correctly do this.
The text was updated successfully, but these errors were encountered: