1.3.6 • Published 5 months ago

propro-auth-middleware v1.3.6

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

propro-auth-middleware

propro-auth-middleware is a comprehensive Node.js middleware designed for handling both server-side and client-side authentication. It's ideal for applications requiring robust authentication strategies and is highly customizable to fit various authentication needs.

Features

  • Dual Authentication Modes: Supports both server-side and client-side authentication.
  • Configurable: Offers a wide range of options for customizing the authentication process.
  • Lazy Loading: Efficiently initializes authentication modules on-demand.
  • Environment Validation: Ensures critical environment variables are set.
  • Error Management: Provides robust error handling during the authentication process.

Installation

Install the middleware using npm or Yarn:

npm install propro-auth-middleware
# or
yarn add propro-auth-middleware

## Usage

After installing the middleware, you can import it in your project:

```javascript
const proproAuthMiddleware = require("propro-auth-middleware");

Then, you can use the middleware in your server and client side code:

const express = require("express");
const app = express();
const proproAuthMiddleware = require("propro-auth-middleware");

// Initialize middleware with default parameters
app.use(proproAuthMiddleware());

// Or, initialize with custom settings
// For example, to use only server authentication:
app.use(proproAuthMiddleware(true, false));

// And to use only client authentication:
app.use(proproAuthMiddleware(false, true));

// Add options
app.use(
  proproAuthMiddleware({
    useServerAuth: true,
    serverOptions: {
      validateUser: async (userId) => {
        /* User validation logic */
      },
    secret = "RESTFULAPIs",
    authUrl = process.env.AUTH_URL,
    clientId = process.env.CLIENT_ID,
    clientSecret = process.env.CLIENT_SECRET,
    clientUrl = process.env.CLIENT_URL,
    redirectUri = process.env.REDIRECT_URI,
      onAuthFailRedirect: "/login",
      additionalChecks: async (req) => {
        /* Additional request checks */
      },
    },
    useClientAuth: false,
    clientOptions: {
      // Client-side authentication options
    },
  })
);

Configuration Options

  • useServerAuth (boolean): Enable or disable server-side authentication.
  • serverOptions (object): Configuration options for server-side authentication.
  • useClientAuth (boolean): Enable or disable client-side authentication.
  • clientOptions (object): Configuration options for client-side authentication.

Contributing

If you have suggestions for how propro-auth-middleware could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

License

ISC © 2023 ProPro devs@hubhub.app

1.3.6

5 months ago

1.3.5

5 months ago

1.3.4

5 months ago

1.3.3

5 months ago

1.3.2

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.9

5 months ago

1.2.8

5 months ago

1.2.7

5 months ago

1.2.6

5 months ago

1.2.5

5 months ago

1.2.4

5 months ago

1.2.3

5 months ago

1.2.2

5 months ago

1.2.0

5 months ago

1.1.9

5 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago