New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aulasoftwarelibre/next-auth-firewall

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aulasoftwarelibre/next-auth-firewall

Firewall for NextAuth

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

RBAC NextAuth.js firewall

⚠️ Warning: This is a Proof of Concept (PoC), and it is not production-ready. Use with caution and provide feedback for improvements. Thanks!

This package is a plugin for NextAuth version 5 that adds a Role-Based Access Control (RBAC) authorization layer to your authentication setup. The RBAC implementation is inspired by Symfony.

Installation

To install the @aulasoftwarelibre/next-auth-firewall package, run:

npm install @aulasoftwarelibre/next-auth-firewall

Setup

Change auth.ts

Replace the content of your auth.ts file with the following code:

import NextAuthFirewall from '@aulasoftwarelibre/next-auth-firewall'
import authConfig from '@/lib/auth/auth.config'

export const {
  auth,
  firewallHandler,
  handlers: { GET, POST },
  signIn,
  signOut,
} = NextAuthFirewall(authConfig)

Change middleware.ts

Update your middleware.ts file with the following code:

import NextAuthFirewall from '@aulasoftwarelibre/next-auth-firewall'
import authConfig from '@/lib/auth/auth.config'

export default NextAuthFirewall(authConfig).auth

export const config = {
  matcher: [
    '/((?!api|_next/static|_next/image|favicon.ico).*)',
  ],
}

Add Firewall Router

Create a new file src/app/api/auth/firewall/route.ts and add the following code:

import { firewallHandler } from '@/lib/auth/auth'

const { POST } = firewallHandler

export { POST }

Update auth.config.ts

Modify your auth.config.ts file to replace the authorize callback with access control rules. Here's an example:

import type { NextAuthFirewallConfig } from '@aulasoftwarelibre/next-auth-firewall'

const authConfig = {
    accessControl: [
        {
            path: '^/(signout|settings)',
            roles: 'IS_AUTHENTICATED',
        },
        {
            path: '^/',
            roles: 'PUBLIC_ACCESS',
        },
    ],
    // ...
} as NextAuthFirewallConfig

export default authConfig

Make sure to configure the adapter as per your requirements.

FAQs

Package last updated on 29 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc