propro-utils 1.3.8 → 1.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/package.json +1 -1
- package/src/server/index.js +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# propro-
|
|
1
|
+
# propro-utils
|
|
2
2
|
|
|
3
|
-
`propro-
|
|
3
|
+
`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.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
Install the middleware using npm or Yarn:
|
|
16
16
|
|
|
17
17
|
````bash
|
|
18
|
-
npm install propro-
|
|
18
|
+
npm install propro-utils
|
|
19
19
|
# or
|
|
20
|
-
yarn add propro-
|
|
20
|
+
yarn add propro-utils
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
After installing the middleware, you can import it in your project:
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
const proproAuthMiddleware = require("propro-
|
|
27
|
+
const proproAuthMiddleware = require("propro-utils");
|
|
28
28
|
````
|
|
29
29
|
|
|
30
30
|
Then, you can use the middleware in your server and client side code:
|
|
@@ -32,7 +32,7 @@ Then, you can use the middleware in your server and client side code:
|
|
|
32
32
|
```javascript
|
|
33
33
|
const express = require("express");
|
|
34
34
|
const app = express();
|
|
35
|
-
const proproAuthMiddleware = require("propro-
|
|
35
|
+
const proproAuthMiddleware = require("propro-utils");
|
|
36
36
|
|
|
37
37
|
// Initialize middleware with default parameters
|
|
38
38
|
app.use(proproAuthMiddleware());
|
|
@@ -80,7 +80,7 @@ app.use(
|
|
|
80
80
|
|
|
81
81
|
## Contributing
|
|
82
82
|
|
|
83
|
-
If you have suggestions for how propro-
|
|
83
|
+
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.
|
|
84
84
|
|
|
85
85
|
For more, check out the [Contributing Guide](./CONTRIBUTING.md).
|
|
86
86
|
|
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -17,12 +17,13 @@ function proproAuthMiddleware(options = {}) {
|
|
|
17
17
|
} = options;
|
|
18
18
|
|
|
19
19
|
return async (req, res, next) => {
|
|
20
|
+
console.log("req.cookies", req.cookies);
|
|
20
21
|
try {
|
|
21
22
|
// Try to get the token from the Authorization header
|
|
22
23
|
let token;
|
|
23
24
|
if (req.headers.authorization?.startsWith("Bearer ")) {
|
|
24
25
|
token = req.headers.authorization.split(" ")[1];
|
|
25
|
-
}
|
|
26
|
+
} else if (req.cookies && req.cookies['x-access-token']) {
|
|
26
27
|
// If not present in Authorization header, try to get it from cookies
|
|
27
28
|
token = req.cookies['x-access-token'];
|
|
28
29
|
}
|
|
@@ -31,7 +32,7 @@ function proproAuthMiddleware(options = {}) {
|
|
|
31
32
|
const verifiedToken = verifyJWT(token, secret);
|
|
32
33
|
if (verifiedToken) {
|
|
33
34
|
req.account = verifiedToken;
|
|
34
|
-
} else {
|
|
35
|
+
} else if (req.cookies && req.cookies['x-refresh-token']) {
|
|
35
36
|
// If token is invalid or expired, try to refresh it
|
|
36
37
|
const refreshToken = req.cookies['x-refresh-token'];
|
|
37
38
|
if (refreshToken) {
|