propro-utils
is a comprehensive Node.js middleware designed for handling both server-side and client-side authentication, notifcations and other utility functions. It's ideal for applications requiring robust authentication strategies and is highly customizable to fit various authentication needs.
- 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.
Install the middleware using npm or Yarn:
npm install propro-utils
# or
yarn add propro-utils
## Usage
After installing the middleware, you can import it in your project:
```javascript
const proproAuthMiddleware = require("propro-utils");
Then, you can use the middleware in your server and client side code:
const express = require("express");
const app = express();
const proproAuthMiddleware = require("propro-utils");
// 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
},
})
);
- 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.
If you have suggestions for how propro-utils 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.
ISC © 2023 ProPro devs@hubhub.app