@cocreate/authenticate 1.4.2 → 1.4.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [1.4.3](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.4.2...v1.4.3) (2023-11-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * date update to ISO format ([eaf2a77](https://github.com/CoCreate-app/CoCreate-authenticate/commit/eaf2a77ff6503021354ae2917279c011ea0fd4f8))
7
+ * meta name typo ([a7299c0](https://github.com/CoCreate-app/CoCreate-authenticate/commit/a7299c0406bbf96e46af9c6e575fe699e4d94773))
8
+ * update crud methods ([e9d0ff0](https://github.com/CoCreate-app/CoCreate-authenticate/commit/e9d0ff09003c2f6e7cde50ec307c3f786bdca0a0))
9
+ * update host ([71a7281](https://github.com/CoCreate-app/CoCreate-authenticate/commit/71a7281a96aa10c79c0e9fcd5a50c852a6d89ef3))
10
+
1
11
  ## [1.4.2](https://github.com/CoCreate-app/CoCreate-authenticate/compare/v1.4.1...v1.4.2) (2023-11-03)
2
12
 
3
13
 
@@ -12,8 +12,7 @@ module.exports = {
12
12
  "pathname": "/docs/authenticate/index.html",
13
13
  "src": "{{./docs/index.html}}",
14
14
  "host": [
15
- "*",
16
- "general.cocreate.app"
15
+ "*"
17
16
  ],
18
17
  "directory": "authenticate",
19
18
  "content-type": "text/html",
package/docs/index.html CHANGED
@@ -11,10 +11,10 @@
11
11
  sizes="32x32"
12
12
  href="https://cocreate.app/images/favicon.ico" />
13
13
  <meta
14
- key="description"
14
+ name="description"
15
15
  content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
16
  <meta
17
- key="keywords"
17
+ name="keywords"
18
18
  content="helper classes, utility classes, css framework, css library, inline style classes" />
19
19
  <meta name="robots" content="index,follow" />
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/authenticate",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "A simple authenticate component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "authenticate",
package/src/index.js CHANGED
@@ -14,12 +14,12 @@ const users = new Map();
14
14
  // TODO: user can have multiple sessions
15
15
  const activeSessions = new Map();
16
16
 
17
- // crud.listen('create.object', function (data) {
17
+ // crud.listen('object.create', function (data) {
18
18
  // if (data.object && data.object[0] && data.object[0].type === 'keyPair')
19
19
  // keyPairs.set(data.object[0]._id, data.object[0]);
20
20
  // });
21
21
 
22
- // crud.listen('delete.object', function (data) {
22
+ // crud.listen('object.delete', function (data) {
23
23
  // if (data.object && data.object[0] && data.object[0].type === 'keyPair')
24
24
  // keyPairs.delete(data.object[0]._id);
25
25
  // });
@@ -30,12 +30,13 @@ function createKeyPair() {
30
30
  modulusLength: 2048,
31
31
  });
32
32
 
33
+ let created = new Date(new Date().toISOString()).getTime()
33
34
  const keyPair = {
34
35
  _id: ObjectId().toString(),
35
36
  privateKey,
36
37
  publicKey,
37
- created: new Date().getTime(), // Store as timestamp
38
- expires: new Date().getTime() + tokenExpiration * 60 * 1000 * 2, // Convert minutes to milliseconds
38
+ created,
39
+ expires: created + tokenExpiration * 60 * 1000, // Convert minutes to milliseconds
39
40
  };
40
41
 
41
42
  keyPairs.set(keyPair._id, keyPair);
@@ -92,7 +93,7 @@ function deleteKeyPair(keyPair) {
92
93
  // Function to sign a new token using the newest keyPair
93
94
  function encodeToken(payload) {
94
95
  let keyPair = null
95
- const currentTime = new Date().getTime();
96
+ const currentTime = new Date(new Date().toISOString()).getTime();
96
97
  for (let [key, value] of keyPairs) {
97
98
  if (currentTime > value.expires) {
98
99
  deleteKeyPair(value);
@@ -108,7 +109,7 @@ function encodeToken(payload) {
108
109
  // TODO: payload could have previous user ip and device information which we could use to comapre to current ip and device information
109
110
 
110
111
  const token = jwt.sign(payload, keyPair.privateKey, { algorithm: 'RS256', expiresIn: tokenExpiration * 60 });
111
- users.set(token, { _id: payload.user_id, expires: new Date().getTime() + tokenExpiration * 60 * 1000 })
112
+ users.set(token, { _id: payload.user_id, expires: currentTime + tokenExpiration * 60 * 1000 })
112
113
  return token;
113
114
  }
114
115