@cocreate/users 1.22.0 → 1.22.2

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,17 @@
1
+ ## [1.22.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.22.1...v1.22.2) (2023-05-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Refactor authentication flow for CoCreateUser ([25bd324](https://github.com/CoCreate-app/CoCreate-users/commit/25bd324bd04d0c196161f4e93b48589c80acee41))
7
+
8
+ ## [1.22.1](https://github.com/CoCreate-app/CoCreate-users/compare/v1.22.0...v1.22.1) (2023-05-21)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Remove unused function from client.js ([11fb260](https://github.com/CoCreate-app/CoCreate-users/commit/11fb2601c31e60b56b9463462dd9a44f70a797d2))
14
+
1
15
  # [1.22.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.21.7...v1.22.0) (2023-05-21)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.22.0",
3
+ "version": "1.22.2",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
@@ -60,11 +60,11 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@cocreate/actions": "^1.8.11",
63
- "@cocreate/crud-client": "^1.21.3",
64
- "@cocreate/docs": "^1.7.11",
63
+ "@cocreate/crud-client": "^1.21.4",
64
+ "@cocreate/docs": "^1.7.12",
65
65
  "@cocreate/element-prototype": "^1.8.11",
66
66
  "@cocreate/form": "^1.14.11",
67
67
  "@cocreate/local-storage": "^1.7.2",
68
- "@cocreate/render": "^1.24.11"
68
+ "@cocreate/render": "^1.24.12"
69
69
  }
70
70
  }
package/src/client.js CHANGED
@@ -11,7 +11,6 @@ const CoCreateUser = {
11
11
  init: function () {
12
12
  this.initSocket();
13
13
  this.initSession();
14
- this.initChangeOrg();
15
14
  },
16
15
 
17
16
  initSocket: function () {
@@ -96,9 +95,9 @@ const CoCreateUser = {
96
95
 
97
96
  let request = {
98
97
  collection,
99
- document: {
100
- lastSignIn: new Date().toISOString()
101
- },
98
+ // document: {
99
+ // lastSignIn: new Date().toISOString()
100
+ // },
102
101
  filter: {
103
102
  query
104
103
  }
@@ -106,12 +105,13 @@ const CoCreateUser = {
106
105
 
107
106
  const socket = crud.socket.getSockets()
108
107
  if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || crud.socket.serverOrganization == false) {
109
- crud.updateDocument(request).then((response) => {
108
+ crud.readDocument(request).then((response) => {
110
109
  response['success'] = false
111
110
  response['status'] = "signIn failed"
112
111
  if (response.document && response.document[0]) {
113
112
  response['success'] = true
114
113
  response['status'] = "success"
114
+ response['user_id'] = response.document[0].key
115
115
  this.signInResponse(response)
116
116
  } else {
117
117
  this.signInResponse(response)
@@ -126,13 +126,13 @@ const CoCreateUser = {
126
126
  },
127
127
 
128
128
  signInResponse: function (data) {
129
- let { success, status, message, token } = data;
129
+ let { success, status, message, user_id, token } = data;
130
130
 
131
131
  if (success) {
132
132
  localStorage.setItem('organization_id', crud.socket.config.organization_id);
133
133
  localStorage.setItem("key", crud.socket.config.key);
134
134
  localStorage.setItem("host", crud.socket.config.host);
135
- localStorage.setItem('user_id', data.document[0]['_id']);
135
+ localStorage.setItem('user_id', user_id);
136
136
  localStorage.setItem("token", token);
137
137
  // document.cookie = `token=${token};path=/`;
138
138
  message = "Succesful signIn";
package/src/server.js CHANGED
@@ -48,41 +48,36 @@ class CoCreateUser {
48
48
  async signIn(socket, data) {
49
49
  const self = this;
50
50
  try {
51
- data.collection = 'keys'
52
- this.crud.updateDocument(data).then(async (data) => {
51
+ this.crud.readDocument(data).then(async (data) => {
53
52
  let response = {
54
- ...data,
55
53
  success: false,
56
54
  message: "signIn failed",
57
55
  status: "failed",
58
56
  userStatus: 'off'
59
57
  }
60
58
 
61
- if (data.document[0] && data.document[0]._id) {
62
- let token = null;
63
- if (self.wsManager.authInstance) {
64
- token = await self.wsManager.authInstance.generateToken({ user_id: data.document[0]._id });
65
- }
59
+ if (data.document[0] && data.document[0]._id && self.wsManager.authInstance) {
60
+ const user_id = data.document[0].key
61
+ const token = await self.wsManager.authInstance.generateToken({ user_id });
66
62
 
67
- if (token && token != 'null')
63
+ if (token && token != 'null') {
68
64
  response = {
69
- ...response,
70
65
  success: true,
71
66
  message: "signIn successful",
72
67
  status: "success",
73
68
  userStatus: 'on',
69
+ user_id,
74
70
  token
75
71
  };
76
72
 
77
-
78
- if (data.organization_id != process.env.organization_id) {
79
- let Data = { organization_id: process.env.organization_id }
80
- Data.document['_id'] = data.document[0]._id
81
- Data.document['lastsignIn'] = data.document[0].lastsignIn
82
- Data.document['organization_id'] = process.env.organization_id
83
- crud.updateDocument(Data)
73
+ // if (data.organization_id != process.env.organization_id) {
74
+ // let Data = { organization_id: process.env.organization_id }
75
+ // Data.document['_id'] = data.document[0]._id
76
+ // Data.document['lastsignIn'] = data.document[0].lastsignIn
77
+ // Data.document['organization_id'] = process.env.organization_id
78
+ // crud.updateDocument(Data)
79
+ // }
84
80
  }
85
-
86
81
  }
87
82
  self.wsManager.send(socket, 'signIn', response)
88
83
  self.wsManager.broadcast(socket, 'updateUserStatus', {