roboto-js 1.1.6 → 1.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/index.js CHANGED
@@ -82,6 +82,9 @@ export default class Roboto{
82
82
  async loadCurrentUser(){
83
83
  return this.api.loadCurrentUser();
84
84
  }
85
+ async confirmUserEmail(params){
86
+ return this.api.confirmUserEmail(params);
87
+ }
85
88
 
86
89
  //
87
90
  // create and upload files
package/src/rbt_api.js CHANGED
@@ -61,6 +61,7 @@ export default class RbtApi {
61
61
  }
62
62
 
63
63
  this.iac_session = response.data;
64
+ this.currentUser = (this.iac_session)? new RbtUser(this.iac_session.user, this.axios): null;
64
65
  // update axios instance headers with authtoken
65
66
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
66
67
 
@@ -87,6 +88,7 @@ export default class RbtApi {
87
88
 
88
89
  // Clear the iac_session and remove the auth token from axios headers
89
90
  this.iac_session = null;
91
+ this.currentUser = null;
90
92
  if (this.axios.defaults.headers.common['authtoken']) {
91
93
  delete this.axios.defaults.headers.common['authtoken'];
92
94
  }
@@ -105,17 +107,48 @@ export default class RbtApi {
105
107
 
106
108
  async loadCurrentUser(){
107
109
 
108
- // TODO - get the actual user from the session
109
- let params = { id: 'superuser_tom' };
110
+ try {
111
+
112
+ if(this.currentUser){
113
+ return this.currentUser;
114
+ }
115
+
116
+ if(this.authtoken){
117
+
118
+ let response = await this.refreshAuthToken(this.authtoken);
119
+ this.currentUser = new RbtUser({ id: response.user.id }, this.axios);
120
+ this.currentUser.setData(response.user);
121
+ return this.currentUser;
122
+
123
+ //this.currentOrg = new RbtObject(response.organization, this.axios);
124
+ //this.currentOrg.type = '<@iac.organization>';
125
+
126
+ }
127
+
128
+ this.currentUser = null;
129
+ return null;
130
+
131
+ }
132
+ catch(e){
133
+ return this._handleError(e);
134
+ }
135
+
136
+ }
137
+
138
+
139
+ async confirmUserEmail(confirmCode){
140
+
141
+ let params = { emailConfirmCode: confirmCode };
110
142
 
111
143
  try {
112
144
 
113
- const response = await this.axios.post('/user_service/loadUser', [params]);
114
- let userData = response?.data?.user;
145
+ const response = await this.axios.post('/user_service/confirmUserEmail', [params]);
146
+
147
+ if (response.data.ok === false) {
148
+ return this._handleError(response);
149
+ }
115
150
 
116
- let User = new RbtUser({ id: userData.id }, this.axios);
117
- User.setData(userData);
118
- return User;
151
+ return response.data;
119
152
 
120
153
  } catch (e) {
121
154
  return this._handleError(e);
@@ -123,6 +156,7 @@ export default class RbtApi {
123
156
 
124
157
  }
125
158
 
159
+
126
160
  async loadUser(userId){
127
161
 
128
162
  let params = { id: userId };
@@ -148,6 +182,8 @@ export default class RbtApi {
148
182
  try {
149
183
 
150
184
  const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
185
+
186
+ debugger;
151
187
  return response.data;
152
188
 
153
189
  } catch (e) {
@@ -167,11 +203,8 @@ export default class RbtApi {
167
203
  async registerUser(dataHash={}) {
168
204
  try {
169
205
  const response = await this.axios.post('/user_service/registerUser', [dataHash]);
170
- const record = response.data;
171
206
 
172
- if(dataHash){
173
- record.data = dataHash;
174
- }
207
+ const record = response.data;
175
208
  return new RbtUser(record, this.axios);
176
209
  } catch (e) {
177
210
  debugger;