
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
fastify-auth-middleware
Advanced tools
Fastify plugin to allow passing RBAC based JWT tokens as a route middleware.
With this Package, you can include RBAC permissions in the JWT token's request header to grant access to specific routes within your fastify project. By leveraging this feature, you can easily apply permissions to private routes.
fastify-auth-middleware offers two key functionalities:
If you'll use this package with Auth0, This package is specifically designed to address Auth0 API Authorization within fastify projects. For implementing Auth0 with Express.js, you can find the necessary resources and documentation Here.
To use this package into your fastify project, follow these simple steps:
npm i fastify-auth-middleware
Installing
import { authPlugin } from 'fastify-auth-middleware';
const server = fastify({
// your fastify configs
});
server.register(authPlugin);
OR
const FastifyAuthMiddleware = require('fastify-auth-middleware');
const server = fastify({
// your fastify configs
});
server.register(FastifyAuthMiddleware.authPlugin);
Protecting Routes
import { authPlugin } from 'fastify-auth-middleware';
const server = fastify({
// your fastify configs
});
// Register the plugin
server.register(authPlugin);
// Public Route - This route doesn't need authentication
server.get('/about', async (req, res) => {
return { message: 'About page' };
});
// A private route with no scope - This route requires authentication but no specific scope
server.get('/posts', { preHandler: [fastify.jwtVerify({})] } , async (req, res) => {
return { message: 'That is fantastic! You now have the ability to access posts.'
});
// A scope protected route
server.get('/actions', { preHandler: [fastify.jwtVerify({ scopes: ['read:actions'] })] } , async (req, res) => {
return { message: 'That is fantastic! You now have the ability to view and read actions.'
});
To avoid encountering the error message "Property 'jwtVerify' does not exist on type 'FastifyInstance<>'", it is necessary to include the 'jwtVerify' property when registering your routes within a Fastify instance.
import { FastifyInstance } from 'fastify';
export interface FastifyInstancePlugin extends FastifyInstance {
jwtVerify?: any;
}
const routes = async (fastify: FastifyInstancePlugin) => {
// your routes
}
If you found an issue or would like to submit an improvement to this project, please submit an issue using the issues tab above. If you would like to submit a PR with a fix, reference the issue you created!
no reported issues so far!
If you are feeling generous, buy me a coffee! - https://www.buymeacoffee.com/fawzytatdev
FAQs
Fastify plugin to allow passing RBAC based JWT tokens as a route middleware.
We found that fastify-auth-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.