Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@this-dot/vue-route-guard
Advanced tools
Vue Route Guard is an Vue library that wraps around the vue-router and extends it to provide helpful methods to handle page guards via token authorization and permissions.
It supports:
✅ Adding guards to pages
✅ Ability to choose between different storage options for storing token
✅ Storing and Retrieving authentication data (user details and token)
✅ Exposes method for checking matching page permission within components and pages
Install the package:
npm install @this-dot/vue-route-guard
or
yarn add @this-dot/vue-route-guard
To get started, we will need to register Vue Route Guard.
It is very simple to add route guard to your Vue app:
Just import the setupGuard
module
import { setupGuard } from '@this-dot/vue-route-guard';
Install the plugin
vue.use(setupGuard(guardConfig));
We extended the default router meta to accept the following fields:
Field | Description | Required | Type |
---|---|---|---|
requiresAuth | Describes if the page requires authentication | true | boolean |
access | Describes the access permissions needed for the route | false | string[] |
setupGuard requires to pass an object with the following fields:
Field | Description | Required | Type |
---|---|---|---|
router | The router instance used in your vue app | true | Router |
token.name | The name used to store and retrieve the token | true | string |
token.storage | Storage type (This defaults to session storage) | false | StorageType |
redirect.noAuthentication | page to redirect to if no token found or fetchAuthentication fails | false | RouteLocationRaw |
redirect.noPermission | page to redirect to if permission is not in route meta access (redirects to noAuthentication if it is not passed) | false | RouteLocationRaw |
redirect.clearAuthentication | page to redirect to after clearing authentication (redirects to noAuthentication if it is not passed) | false | RouteLocationRaw |
options.fetchAuthentication | This is expects function that returns an object with the authentication information | true | Promise<{}> |
options.permissionKey | Describes the field that holds the authentication permission in fetchAuthentication (default permission) | false | string |
Create a sample router and guard configuration:
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: () => import('../views/HomeView.vue'),
meta: { requiresAuth: true },
},
{
path: '/login',
name: 'login',
component: () => import('../views/LoginView.vue'),
meta: { requiresAuth: false },
},
{
path: '/about',
name: 'about',
component: () => import('../views/AboutView.vue'),
meta: {
requiresAuth: true,
access: ['admin'],
},
},
{
path: '/no-permission',
name: 'no-permission',
component: () => import('../views/NoPermissionView.vue'),
meta: {
requiresAuth: false,
},
},
],
});
const guardConfig = {
router: router,
token: {
name: 'XSRF-TOKEN',
},
redirect: {
noAuthentication: '/login',
clearAuthentication: '/login',
noPermission: '/no-permission',
},
options: {
fetchAuthentication: () => {
return new Promise(function (resolve, reject) {
return resolve({
firstName: 'firstName',
lastName: 'lastName',
login: true,
permission: ['user'],
});
});
},
},
};
vue.use(setupGuard(guardConfig));
Create a guard config using token.
expires
: it can be a valid date string or a number to represent the days
path
: page path for cookie
const guardConfig = {
router: router,
token: {
name: 'XSRF-TOKEN',
storage: StorageType.cookieStorage,
attributes: {
path: '/',
expires: 2, // cookie to expire in 2 days
},
},
redirect: {
noAuthentication: '/login',
clearAuthentication: '/login',
noPermission: '/no-permission',
},
options: {
fetchAuthentication: () => {
return new Promise(function (resolve, reject) {
return resolve({
firstName: 'firstName',
lastName: 'lastName',
login: true,
permission: ['user'],
});
});
},
},
};
<template>
<div>{{ auth.$store.state.authentication }}</div>
</template>
<script setup lang="ts">
import { useGuard } from '@this-dot/vue-route-guard';
const auth = useGuard();
</script>
<script setup lang="ts">
import { useGuard } from '@this-dot/vue-route-guard';
const auth = useGuard();
const logout = () => {
auth.clearAuthentication().then(() => {
console.log('cleared authentication');
});
};
</script>
This calls fetch authentication and updates the state with the new authentication details
<template>
<div>
<span>{{ auth.$store.state.authentication }}</span>
<button @click="updateAuthentiationInformation">Update</button>
</div>
</template>
<script setup lang="ts">
import { useGuard } from '@this-dot/vue-route-guard';
const auth = useGuard();
const updateAuthentiationInformation = () => {
auth.refreshAuthentication();
};
</script>
hasAuthenticationAccess
can be accessed from useGuard and called to check if user has access to specific permission
<template>
<header>
<div class="wrapper">
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink v-if="auth.hasAuthenticationAccess(['admin'])" to="/about">About</RouterLink>
</nav>
</div>
</header>
<RouterView />
</template>
<script setup lang="ts">
import { useGuard } from '@ds-library/ui';
const auth = useGuard();
</script>
FAQs
Vuejs helper library for adding guards to route
We found that @this-dot/vue-route-guard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.