propro-auth-middleware
v1.3.6
Published
Auth middleware for propro-auth
Downloads
22
Readme
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 [email protected]