@stokr/components-library 1.1.8-beta.6 → 1.1.8-beta.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.
|
@@ -40,7 +40,8 @@ var LoginWithOTP = function LoginWithOTP(_ref) {
|
|
|
40
40
|
loginUser = _useContext.loginUser,
|
|
41
41
|
waitingFor2fa = _useContext.waitingFor2fa,
|
|
42
42
|
firebaseError = _useContext.firebaseError,
|
|
43
|
-
loginUserWithTotp = _useContext.loginUserWithTotp
|
|
43
|
+
loginUserWithTotp = _useContext.loginUserWithTotp,
|
|
44
|
+
getUser = _useContext.getUser;
|
|
44
45
|
var _useState = (0, _react.useState)({
|
|
45
46
|
login: true,
|
|
46
47
|
enter2fa: false,
|
|
@@ -143,10 +144,13 @@ var LoginWithOTP = function LoginWithOTP(_ref) {
|
|
|
143
144
|
_context.next = 10;
|
|
144
145
|
return loginUser(email, password);
|
|
145
146
|
case 10:
|
|
146
|
-
_context.next =
|
|
147
|
-
|
|
147
|
+
_context.next = 12;
|
|
148
|
+
return getUser();
|
|
148
149
|
case 12:
|
|
149
|
-
_context.
|
|
150
|
+
_context.next = 19;
|
|
151
|
+
break;
|
|
152
|
+
case 14:
|
|
153
|
+
_context.prev = 14;
|
|
150
154
|
_context.t0 = _context["catch"](3);
|
|
151
155
|
errorMessage = _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message;
|
|
152
156
|
if (errorMessage) {
|
|
@@ -155,11 +159,11 @@ var LoginWithOTP = function LoginWithOTP(_ref) {
|
|
|
155
159
|
handleSetPopupError('login', "Oops. Something's not right there. Try again?");
|
|
156
160
|
}
|
|
157
161
|
setIsActionLoading(undefined);
|
|
158
|
-
case
|
|
162
|
+
case 19:
|
|
159
163
|
case "end":
|
|
160
164
|
return _context.stop();
|
|
161
165
|
}
|
|
162
|
-
}, _callee, null, [[3,
|
|
166
|
+
}, _callee, null, [[3, 14]]);
|
|
163
167
|
}));
|
|
164
168
|
return function (_x) {
|
|
165
169
|
return _ref3.apply(this, arguments);
|
|
@@ -193,10 +197,13 @@ var LoginWithOTP = function LoginWithOTP(_ref) {
|
|
|
193
197
|
_context2.next = 5;
|
|
194
198
|
return loginUserWithTotp(otpInput, firebaseError);
|
|
195
199
|
case 5:
|
|
196
|
-
_context2.next =
|
|
197
|
-
|
|
200
|
+
_context2.next = 7;
|
|
201
|
+
return getUser();
|
|
198
202
|
case 7:
|
|
199
|
-
_context2.
|
|
203
|
+
_context2.next = 13;
|
|
204
|
+
break;
|
|
205
|
+
case 9:
|
|
206
|
+
_context2.prev = 9;
|
|
200
207
|
_context2.t0 = _context2["catch"](2);
|
|
201
208
|
console.log('🚀 ~ file: login-with-otp-flow.js:129 ~ error:', _context2.t0);
|
|
202
209
|
if ((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.code) === 'auth/invalid-verification-code') {
|
|
@@ -204,13 +211,13 @@ var LoginWithOTP = function LoginWithOTP(_ref) {
|
|
|
204
211
|
} else {
|
|
205
212
|
handleSetPopupError('enter2fa', _context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.message);
|
|
206
213
|
}
|
|
207
|
-
case
|
|
214
|
+
case 13:
|
|
208
215
|
setIsActionLoading(undefined);
|
|
209
|
-
case
|
|
216
|
+
case 14:
|
|
210
217
|
case "end":
|
|
211
218
|
return _context2.stop();
|
|
212
219
|
}
|
|
213
|
-
}, _callee2, null, [[2,
|
|
220
|
+
}, _callee2, null, [[2, 9]]);
|
|
214
221
|
}));
|
|
215
222
|
return function (_x2) {
|
|
216
223
|
return _ref5.apply(this, arguments);
|
|
@@ -60,10 +60,12 @@ var ForgotPasswordModal = /*#__PURE__*/function (_PureComponent) {
|
|
|
60
60
|
onModalSwitch = _this$props.onModalSwitch,
|
|
61
61
|
popupError = _this$props.popupError,
|
|
62
62
|
popupSuccess = _this$props.popupSuccess,
|
|
63
|
-
isActionLoading = _this$props.isActionLoading
|
|
63
|
+
isActionLoading = _this$props.isActionLoading,
|
|
64
|
+
background = _this$props.background;
|
|
64
65
|
return /*#__PURE__*/_react.default.createElement(_Modal.Modal, {
|
|
65
66
|
isOpen: isModalOpen,
|
|
66
|
-
onClose: onModalClose
|
|
67
|
+
onClose: onModalClose,
|
|
68
|
+
background: background
|
|
67
69
|
}, /*#__PURE__*/_react.default.createElement(_Grid.Row, null, /*#__PURE__*/_react.default.createElement(_Grid.Column, {
|
|
68
70
|
part: 8
|
|
69
71
|
}, /*#__PURE__*/_react.default.createElement(_Modal.ModalInner, {
|
|
@@ -336,33 +336,35 @@ var HeaderHoClass = /*#__PURE__*/function (_Component) {
|
|
|
336
336
|
setIsLoginModalOpen && setIsLoginModalOpen(false);
|
|
337
337
|
_this2.clearPopupError();
|
|
338
338
|
_this2.setIsActionLoading(undefined);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
break;
|
|
339
|
+
_context.next = 16;
|
|
340
|
+
return getUser();
|
|
342
341
|
case 16:
|
|
343
|
-
_context.
|
|
342
|
+
_context.next = 28;
|
|
343
|
+
break;
|
|
344
|
+
case 18:
|
|
345
|
+
_context.prev = 18;
|
|
344
346
|
_context.t0 = _context["catch"](3);
|
|
345
347
|
errorMessage = _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message; //handle switch modal correctly
|
|
346
348
|
if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) === 'auth/multi-factor-auth-required')) {
|
|
347
|
-
_context.next =
|
|
349
|
+
_context.next = 26;
|
|
348
350
|
break;
|
|
349
351
|
}
|
|
350
352
|
_this2.switchOpenModal('login', 'enter2fa');
|
|
351
353
|
_this2.clearPopupError();
|
|
352
354
|
_this2.setIsActionLoading(undefined);
|
|
353
355
|
return _context.abrupt("return");
|
|
354
|
-
case
|
|
356
|
+
case 26:
|
|
355
357
|
if (errorMessage) {
|
|
356
358
|
_this2.setPopupError('login', errorMessage);
|
|
357
359
|
} else {
|
|
358
360
|
_this2.setPopupError('login', "Oops. Something's not right there. Try again?");
|
|
359
361
|
}
|
|
360
362
|
_this2.setIsActionLoading(undefined);
|
|
361
|
-
case
|
|
363
|
+
case 28:
|
|
362
364
|
case "end":
|
|
363
365
|
return _context.stop();
|
|
364
366
|
}
|
|
365
|
-
}, _callee, null, [[3,
|
|
367
|
+
}, _callee, null, [[3, 18]]);
|
|
366
368
|
}));
|
|
367
369
|
return function (_x) {
|
|
368
370
|
return _ref3.apply(this, arguments);
|
|
@@ -395,10 +397,13 @@ var HeaderHoClass = /*#__PURE__*/function (_Component) {
|
|
|
395
397
|
_context2.next = 5;
|
|
396
398
|
return loginUserWithTotp(otpInput, firebaseError);
|
|
397
399
|
case 5:
|
|
398
|
-
_context2.next =
|
|
399
|
-
|
|
400
|
+
_context2.next = 7;
|
|
401
|
+
return getUser();
|
|
400
402
|
case 7:
|
|
401
|
-
_context2.
|
|
403
|
+
_context2.next = 13;
|
|
404
|
+
break;
|
|
405
|
+
case 9:
|
|
406
|
+
_context2.prev = 9;
|
|
402
407
|
_context2.t0 = _context2["catch"](2);
|
|
403
408
|
console.log('🚀 ~ file: HeaderHo.jsx:364 ~ error:', _context2.t0);
|
|
404
409
|
if ((_context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.code) === 'auth/invalid-verification-code') {
|
|
@@ -406,13 +411,13 @@ var HeaderHoClass = /*#__PURE__*/function (_Component) {
|
|
|
406
411
|
} else {
|
|
407
412
|
_this2.setPopupError('enter2fa', _context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.message);
|
|
408
413
|
}
|
|
409
|
-
case
|
|
414
|
+
case 13:
|
|
410
415
|
_this2.setIsActionLoading(undefined);
|
|
411
|
-
case
|
|
416
|
+
case 14:
|
|
412
417
|
case "end":
|
|
413
418
|
return _context2.stop();
|
|
414
419
|
}
|
|
415
|
-
}, _callee2, null, [[2,
|
|
420
|
+
}, _callee2, null, [[2, 9]]);
|
|
416
421
|
}));
|
|
417
422
|
return function (_x2) {
|
|
418
423
|
return _ref5.apply(this, arguments);
|
package/dist/context/Auth.js
CHANGED
|
@@ -99,6 +99,19 @@ var Auth = /*#__PURE__*/function () {
|
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "getFirebaseUser",
|
|
104
|
+
value: function getFirebaseUser() {
|
|
105
|
+
return new Promise(function (resolve, reject) {
|
|
106
|
+
(0, _auth.onAuthStateChanged)(_firebaseConfig.auth, function (user) {
|
|
107
|
+
if (user) {
|
|
108
|
+
resolve(user);
|
|
109
|
+
} else {
|
|
110
|
+
reject('User is signed out');
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
102
115
|
}, {
|
|
103
116
|
key: "requestUpdateEmail",
|
|
104
117
|
value: function requestUpdateEmail(data) {
|
|
@@ -45,6 +45,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
45
45
|
args[_key] = arguments[_key];
|
|
46
46
|
}
|
|
47
47
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this), "userRef", /*#__PURE__*/_react.default.createRef(null));
|
|
48
49
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
49
50
|
user: undefined,
|
|
50
51
|
firebaseUser: undefined,
|
|
@@ -54,7 +55,6 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
54
55
|
waitingFor2fa: false,
|
|
55
56
|
firebaseError: null
|
|
56
57
|
});
|
|
57
|
-
_defineProperty(_assertThisInitialized(_this), "userRef", /*#__PURE__*/_react.default.createRef(null));
|
|
58
58
|
_defineProperty(_assertThisInitialized(_this), "checkTokenIsValid", function () {
|
|
59
59
|
var redirect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
60
60
|
var accessToken = _Auth.default.getAccessToken();
|
|
@@ -74,46 +74,44 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
74
74
|
return _Auth.default.login(email, password);
|
|
75
75
|
case 3:
|
|
76
76
|
user = _context.sent;
|
|
77
|
-
console.log('🚀 ~ file: AuthContext.js:33 ~ user:', user);
|
|
78
77
|
_Auth.default.setAccessToken(user.accessToken);
|
|
79
|
-
_axios.default.defaults.headers.common.Authorization = "Bearer ".concat(user.accessToken);
|
|
80
|
-
_this.setUser(user);
|
|
81
78
|
_this.setState({
|
|
79
|
+
firebaseUser: user,
|
|
82
80
|
isFetchingUser: false
|
|
83
81
|
});
|
|
84
82
|
//if you need user immediatly
|
|
85
83
|
return _context.abrupt("return", user);
|
|
86
|
-
case
|
|
87
|
-
_context.prev =
|
|
84
|
+
case 9:
|
|
85
|
+
_context.prev = 9;
|
|
88
86
|
_context.t0 = _context["catch"](0);
|
|
89
87
|
console.log('🚀 ~ file: AuthContext.js:56 ~ error:', _context.t0);
|
|
90
88
|
_context.t1 = _context.t0.code;
|
|
91
|
-
_context.next = _context.t1 === 'auth/multi-factor-auth-required' ?
|
|
89
|
+
_context.next = _context.t1 === 'auth/multi-factor-auth-required' ? 15 : _context.t1 === 'auth/requires-recent-login' ? 17 : _context.t1 === 'auth/invalid-login-credentials' ? 19 : 21;
|
|
92
90
|
break;
|
|
93
|
-
case
|
|
91
|
+
case 15:
|
|
94
92
|
// Initiate your second factor sign-in flow. (See next step.)
|
|
95
93
|
_this.setState({
|
|
96
94
|
waitingFor2fa: true,
|
|
97
95
|
firebaseError: _context.t0
|
|
98
96
|
});
|
|
99
97
|
throw _context.t0;
|
|
100
|
-
case
|
|
98
|
+
case 17:
|
|
101
99
|
// The user's last sign-in time does not meet the security threshold.
|
|
102
100
|
_this.logoutUser();
|
|
103
|
-
return _context.abrupt("break",
|
|
104
|
-
case
|
|
101
|
+
return _context.abrupt("break", 24);
|
|
102
|
+
case 19:
|
|
105
103
|
_context.t0.message = 'The credentials are not correct. Try again?';
|
|
106
104
|
throw _context.t0;
|
|
107
|
-
case
|
|
105
|
+
case 21:
|
|
108
106
|
console.log({
|
|
109
107
|
error: _context.t0
|
|
110
108
|
}); // Handle other errors, such as wrong passwords.
|
|
111
109
|
throw _context.t0;
|
|
112
|
-
case
|
|
110
|
+
case 24:
|
|
113
111
|
case "end":
|
|
114
112
|
return _context.stop();
|
|
115
113
|
}
|
|
116
|
-
}, _callee, null, [[0,
|
|
114
|
+
}, _callee, null, [[0, 9]]);
|
|
117
115
|
}));
|
|
118
116
|
return function (_x, _x2) {
|
|
119
117
|
return _ref.apply(this, arguments);
|
|
@@ -129,7 +127,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
129
127
|
//console.log(enrolledFactors);
|
|
130
128
|
selectedIndex = 0;
|
|
131
129
|
_context2.t0 = mfaResolver.hints[selectedIndex].factorId;
|
|
132
|
-
_context2.next = _context2.t0 === _auth.TotpMultiFactorGenerator.FACTOR_ID ? 5 : _context2.t0 === _auth.PhoneMultiFactorGenerator.FACTOR_ID ?
|
|
130
|
+
_context2.next = _context2.t0 === _auth.TotpMultiFactorGenerator.FACTOR_ID ? 5 : _context2.t0 === _auth.PhoneMultiFactorGenerator.FACTOR_ID ? 21 : 22;
|
|
133
131
|
break;
|
|
134
132
|
case 5:
|
|
135
133
|
otpFromAuthenticator = verificationCode; // OTP typed by the user.
|
|
@@ -141,31 +139,30 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
141
139
|
userCredential = _context2.sent;
|
|
142
140
|
user = userCredential.user;
|
|
143
141
|
_Auth.default.setAccessToken(user.accessToken);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
_context2.next = 22;
|
|
142
|
+
_this.setState({
|
|
143
|
+
firebaseUser: user
|
|
144
|
+
});
|
|
145
|
+
_context2.next = 20;
|
|
149
146
|
break;
|
|
150
|
-
case
|
|
151
|
-
_context2.prev =
|
|
147
|
+
case 16:
|
|
148
|
+
_context2.prev = 16;
|
|
152
149
|
_context2.t1 = _context2["catch"](7);
|
|
153
150
|
// Invalid or expired OTP.
|
|
154
151
|
console.log({
|
|
155
152
|
error: _context2.t1
|
|
156
153
|
});
|
|
157
154
|
throw _context2.t1;
|
|
155
|
+
case 20:
|
|
156
|
+
return _context2.abrupt("break", 23);
|
|
157
|
+
case 21:
|
|
158
|
+
return _context2.abrupt("break", 23);
|
|
158
159
|
case 22:
|
|
159
|
-
return _context2.abrupt("break",
|
|
160
|
+
return _context2.abrupt("break", 23);
|
|
160
161
|
case 23:
|
|
161
|
-
return _context2.abrupt("break", 25);
|
|
162
|
-
case 24:
|
|
163
|
-
return _context2.abrupt("break", 25);
|
|
164
|
-
case 25:
|
|
165
162
|
case "end":
|
|
166
163
|
return _context2.stop();
|
|
167
164
|
}
|
|
168
|
-
}, _callee2, null, [[7,
|
|
165
|
+
}, _callee2, null, [[7, 16]]);
|
|
169
166
|
}));
|
|
170
167
|
return function (_x3, _x4) {
|
|
171
168
|
return _ref2.apply(this, arguments);
|
|
@@ -338,60 +335,92 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
338
335
|
window.location.href = "https://".concat(process.env.REACT_APP_WEBSITE_DOMAIN);
|
|
339
336
|
}
|
|
340
337
|
});
|
|
341
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
342
|
-
|
|
343
|
-
var customValidateGetUser, _yield$Auth$getUser, user, userAvatar;
|
|
344
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
345
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
346
|
-
case 0:
|
|
347
|
-
if (accessToken) {
|
|
348
|
-
_context7.next = 2;
|
|
349
|
-
break;
|
|
350
|
-
}
|
|
351
|
-
return _context7.abrupt("return");
|
|
352
|
-
case 2:
|
|
353
|
-
//pass this function as a prop if you need any custom logic after user/get
|
|
354
|
-
customValidateGetUser = _this.props.customValidateGetUser;
|
|
355
|
-
_axios.default.defaults.headers.common.Authorization = "Bearer ".concat(accessToken);
|
|
356
|
-
_context7.prev = 4;
|
|
357
|
-
_context7.next = 7;
|
|
358
|
-
return _Auth.default.getUser();
|
|
359
|
-
case 7:
|
|
360
|
-
_yield$Auth$getUser = _context7.sent;
|
|
361
|
-
user = _yield$Auth$getUser.user;
|
|
362
|
-
//if user hasn't completed the signup process, redirect to welcome page on signup
|
|
363
|
-
_this.checkUserIsValid(user);
|
|
364
|
-
customValidateGetUser && customValidateGetUser(user);
|
|
365
|
-
userAvatar = "".concat(process.env.REACT_APP_PHOTO_API_URL, "/media/picture/view/").concat(user._id);
|
|
366
|
-
_this.checkUserPhoto(userAvatar);
|
|
367
|
-
_this.setUser(user);
|
|
368
|
-
_this.setState({
|
|
369
|
-
isFetchingUser: false
|
|
370
|
-
});
|
|
338
|
+
_defineProperty(_assertThisInitialized(_this), "patchUserObject", function (user, firebaseUser) {
|
|
339
|
+
if (!user || !firebaseUser) return;
|
|
371
340
|
|
|
372
|
-
|
|
373
|
-
|
|
341
|
+
//use emailVerified as source of truth for user.active
|
|
342
|
+
user.active = firebaseUser.emailVerified;
|
|
374
343
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
344
|
+
//use Object.assign so that we copy the prototype object from firebaseUser
|
|
345
|
+
//user object will override any properties that are the same in the firebaseUser
|
|
346
|
+
return Object.assign(firebaseUser, user);
|
|
347
|
+
});
|
|
348
|
+
_defineProperty(_assertThisInitialized(_this), "getUser", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
349
|
+
var accessToken,
|
|
350
|
+
customValidateGetUser,
|
|
351
|
+
result,
|
|
352
|
+
firebaseUser,
|
|
353
|
+
user,
|
|
354
|
+
userAvatar,
|
|
355
|
+
_args7 = arguments;
|
|
356
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
357
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
358
|
+
case 0:
|
|
359
|
+
accessToken = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : _Auth.default.getAccessToken();
|
|
360
|
+
if (accessToken) {
|
|
361
|
+
_context7.next = 4;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
_this.setState({
|
|
365
|
+
isFetchingUser: false
|
|
366
|
+
});
|
|
367
|
+
return _context7.abrupt("return");
|
|
368
|
+
case 4:
|
|
369
|
+
_axios.default.defaults.headers.common.Authorization = "Bearer ".concat(accessToken);
|
|
370
|
+
|
|
371
|
+
//pass this function as a prop if you need any custom logic after user/get
|
|
372
|
+
customValidateGetUser = _this.props.customValidateGetUser;
|
|
373
|
+
_context7.prev = 6;
|
|
374
|
+
_context7.next = 9;
|
|
375
|
+
return _Auth.default.getUser();
|
|
376
|
+
case 9:
|
|
377
|
+
result = _context7.sent;
|
|
378
|
+
firebaseUser = _this.state.firebaseUser;
|
|
379
|
+
if (firebaseUser) {
|
|
380
|
+
_context7.next = 15;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
_context7.next = 14;
|
|
384
|
+
return _Auth.default.getFirebaseUser();
|
|
385
|
+
case 14:
|
|
386
|
+
firebaseUser = _context7.sent;
|
|
387
|
+
case 15:
|
|
388
|
+
console.log('🚀 ~ file: AuthContext.js:252 ~ firebaseUser:', firebaseUser);
|
|
389
|
+
|
|
390
|
+
//merge firebaseUser and our user object
|
|
391
|
+
user = _this.patchUserObject(result.user, firebaseUser);
|
|
392
|
+
console.log('🚀 ~ file: AuthContext.js:259 ~ user:', user);
|
|
393
|
+
|
|
394
|
+
//if user is empty throw an error
|
|
395
|
+
//if user hasn't completed the signup process, redirect to welcome page on signup
|
|
396
|
+
_this.checkUserIsValid(user);
|
|
397
|
+
customValidateGetUser && customValidateGetUser(user);
|
|
398
|
+
userAvatar = "".concat(process.env.REACT_APP_PHOTO_API_URL, "/media/picture/view/").concat(user._id);
|
|
399
|
+
_this.checkUserPhoto(userAvatar);
|
|
400
|
+
_this.setUser(user);
|
|
401
|
+
_this.setState({
|
|
402
|
+
isFetchingUser: false
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
//redirect to home if user is on login or signup route (affects homepage only)
|
|
406
|
+
_this.replaceLocationPathName();
|
|
407
|
+
|
|
408
|
+
//if you need user info immediately after call (before setState is executed), you can use this
|
|
409
|
+
return _context7.abrupt("return", user);
|
|
410
|
+
case 28:
|
|
411
|
+
_context7.prev = 28;
|
|
412
|
+
_context7.t0 = _context7["catch"](6);
|
|
413
|
+
_this.setState({
|
|
414
|
+
isFetchingUser: false
|
|
415
|
+
});
|
|
416
|
+
console.log("Error in getUser: ".concat(_context7.t0));
|
|
417
|
+
throw _context7.t0;
|
|
418
|
+
case 33:
|
|
419
|
+
case "end":
|
|
420
|
+
return _context7.stop();
|
|
421
|
+
}
|
|
422
|
+
}, _callee7, null, [[6, 28]]);
|
|
423
|
+
})));
|
|
395
424
|
_defineProperty(_assertThisInitialized(_this), "checkUserPhoto", function (avatar) {
|
|
396
425
|
try {
|
|
397
426
|
var http = new XMLHttpRequest();
|
|
@@ -409,13 +438,9 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
409
438
|
}
|
|
410
439
|
});
|
|
411
440
|
_defineProperty(_assertThisInitialized(_this), "checkUserIsValid", function (user) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
// ) {
|
|
416
|
-
// window.location.href = `https://admin.${process.env.REACT_APP_WEBSITE_DOMAIN}`
|
|
417
|
-
// return false
|
|
418
|
-
// }
|
|
441
|
+
if (!user) {
|
|
442
|
+
throw new Error('User is not defined');
|
|
443
|
+
}
|
|
419
444
|
if (!(user !== null && user !== void 0 && user.country) && (user === null || user === void 0 ? void 0 : user.user_type) === 'investor') {
|
|
420
445
|
window.location.href = "https://signup.".concat(process.env.REACT_APP_WEBSITE_DOMAIN, "/welcome");
|
|
421
446
|
return false;
|
|
@@ -461,7 +486,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
461
486
|
}
|
|
462
487
|
}, _callee8, null, [[0, 14]]);
|
|
463
488
|
}));
|
|
464
|
-
return function (
|
|
489
|
+
return function (_x10, _x11) {
|
|
465
490
|
return _ref8.apply(this, arguments);
|
|
466
491
|
};
|
|
467
492
|
}());
|
|
@@ -524,7 +549,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
524
549
|
}
|
|
525
550
|
}, _callee10, null, [[0, 8]]);
|
|
526
551
|
}));
|
|
527
|
-
return function (
|
|
552
|
+
return function (_x12) {
|
|
528
553
|
return _ref10.apply(this, arguments);
|
|
529
554
|
};
|
|
530
555
|
}());
|
|
@@ -582,7 +607,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
582
607
|
}
|
|
583
608
|
}, _callee11, null, [[4, 19]]);
|
|
584
609
|
}));
|
|
585
|
-
return function (
|
|
610
|
+
return function (_x13) {
|
|
586
611
|
return _ref11.apply(this, arguments);
|
|
587
612
|
};
|
|
588
613
|
}());
|
|
@@ -639,7 +664,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
639
664
|
}
|
|
640
665
|
}, _callee12, null, [[4, 18]]);
|
|
641
666
|
}));
|
|
642
|
-
return function (
|
|
667
|
+
return function (_x14) {
|
|
643
668
|
return _ref12.apply(this, arguments);
|
|
644
669
|
};
|
|
645
670
|
}());
|
|
@@ -665,7 +690,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
665
690
|
}
|
|
666
691
|
}, _callee13, null, [[0, 5]]);
|
|
667
692
|
}));
|
|
668
|
-
return function (
|
|
693
|
+
return function (_x15) {
|
|
669
694
|
return _ref13.apply(this, arguments);
|
|
670
695
|
};
|
|
671
696
|
}());
|
|
@@ -715,7 +740,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
715
740
|
}
|
|
716
741
|
}, _callee15, null, [[0, 7]]);
|
|
717
742
|
}));
|
|
718
|
-
return function (
|
|
743
|
+
return function (_x16, _x17) {
|
|
719
744
|
return _ref15.apply(this, arguments);
|
|
720
745
|
};
|
|
721
746
|
}());
|
|
@@ -737,7 +762,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
737
762
|
}
|
|
738
763
|
}, _callee16, null, [[0, 4]]);
|
|
739
764
|
}));
|
|
740
|
-
return function (
|
|
765
|
+
return function (_x18) {
|
|
741
766
|
return _ref16.apply(this, arguments);
|
|
742
767
|
};
|
|
743
768
|
}());
|
|
@@ -764,11 +789,13 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
764
789
|
}
|
|
765
790
|
}, _callee17, null, [[0, 7]]);
|
|
766
791
|
}));
|
|
767
|
-
return function (
|
|
792
|
+
return function (_x19) {
|
|
768
793
|
return _ref17.apply(this, arguments);
|
|
769
794
|
};
|
|
770
795
|
}());
|
|
771
796
|
_defineProperty(_assertThisInitialized(_this), "setUser", function (user) {
|
|
797
|
+
//there are a few cases where we need user object in event handlers (that don't have access to updated state)
|
|
798
|
+
//that's why we store it in a ref
|
|
772
799
|
_this.userRef.current = user;
|
|
773
800
|
_this.setState({
|
|
774
801
|
user: user
|
|
@@ -805,7 +832,7 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
805
832
|
}
|
|
806
833
|
}, _callee18, null, [[0, 9]]);
|
|
807
834
|
}));
|
|
808
|
-
return function (_x21, _x22
|
|
835
|
+
return function (_x20, _x21, _x22) {
|
|
809
836
|
return _ref18.apply(this, arguments);
|
|
810
837
|
};
|
|
811
838
|
}());
|
|
@@ -815,17 +842,10 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
815
842
|
key: "componentDidMount",
|
|
816
843
|
value: function componentDidMount() {
|
|
817
844
|
var isActivatingUser = window.location.href.includes('/activateUser');
|
|
818
|
-
var accessToken = _Auth.default.getAccessToken();
|
|
819
845
|
if (isActivatingUser) {
|
|
820
846
|
this.activateUser();
|
|
821
|
-
} else if (accessToken) {
|
|
822
|
-
this.getUser(accessToken);
|
|
823
847
|
} else {
|
|
824
|
-
this.
|
|
825
|
-
isFetchingUser: false
|
|
826
|
-
});
|
|
827
|
-
console.log('No access token');
|
|
828
|
-
//window.location.href = `https://${process.env.REACT_APP_WEBSITE_DOMAIN}/login`
|
|
848
|
+
this.getUser();
|
|
829
849
|
}
|
|
830
850
|
}
|
|
831
851
|
}, {
|