@stokr/components-library 2.1.2-beta.1 β 2.1.2-beta.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.
|
@@ -38,7 +38,8 @@ var Enable2FAFlow = function Enable2FAFlow(_ref) {
|
|
|
38
38
|
var _useContext = (0, _react.useContext)(_AuthContext.AuthContext),
|
|
39
39
|
user = _useContext.user,
|
|
40
40
|
generateTotpSecret = _useContext.generateTotpSecret,
|
|
41
|
-
enrollUserToTotp = _useContext.enrollUserToTotp
|
|
41
|
+
enrollUserToTotp = _useContext.enrollUserToTotp,
|
|
42
|
+
refreshIdToken = _useContext.refreshIdToken;
|
|
42
43
|
var _useState = (0, _react.useState)(false),
|
|
43
44
|
_useState2 = _slicedToArray(_useState, 2),
|
|
44
45
|
showSuccess = _useState2[0],
|
|
@@ -51,7 +52,32 @@ var Enable2FAFlow = function Enable2FAFlow(_ref) {
|
|
|
51
52
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
52
53
|
popupError = _useState4[0],
|
|
53
54
|
setpopupError = _useState4[1];
|
|
54
|
-
|
|
55
|
+
(0, _react.useEffect)(function () {
|
|
56
|
+
if (user) {
|
|
57
|
+
refreshToken();
|
|
58
|
+
}
|
|
59
|
+
}, [user]);
|
|
60
|
+
var refreshToken = /*#__PURE__*/function () {
|
|
61
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
62
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
63
|
+
while (1) switch (_context.prev = _context.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
try {
|
|
66
|
+
refreshIdToken();
|
|
67
|
+
console.log('RefreshIdTOken called');
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.log('π ~ error:', error);
|
|
70
|
+
}
|
|
71
|
+
case 1:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context.stop();
|
|
74
|
+
}
|
|
75
|
+
}, _callee);
|
|
76
|
+
}));
|
|
77
|
+
return function refreshToken() {
|
|
78
|
+
return _ref2.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
}();
|
|
55
81
|
// useEffect(() => {
|
|
56
82
|
// if (user) {
|
|
57
83
|
// generateTotpSecret(user)
|
|
@@ -72,66 +98,66 @@ var Enable2FAFlow = function Enable2FAFlow(_ref) {
|
|
|
72
98
|
// }, [user])
|
|
73
99
|
|
|
74
100
|
var onSubmit = /*#__PURE__*/function () {
|
|
75
|
-
var
|
|
76
|
-
return _regeneratorRuntime().wrap(function
|
|
77
|
-
while (1) switch (
|
|
101
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
|
|
102
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
103
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
78
104
|
case 0:
|
|
79
105
|
if (!(!user || !data)) {
|
|
80
|
-
|
|
106
|
+
_context2.next = 2;
|
|
81
107
|
break;
|
|
82
108
|
}
|
|
83
|
-
return
|
|
109
|
+
return _context2.abrupt("return", console.log('not enough data'));
|
|
84
110
|
case 2:
|
|
85
|
-
|
|
86
|
-
|
|
111
|
+
_context2.prev = 2;
|
|
112
|
+
_context2.next = 5;
|
|
87
113
|
return enrollUserToTotp(user, totpData.totpSecret, data.otpInput, user.displayName);
|
|
88
114
|
case 5:
|
|
89
115
|
setshowSuccess(true);
|
|
90
|
-
|
|
91
|
-
|
|
116
|
+
_context2.prev = 6;
|
|
117
|
+
_context2.next = 9;
|
|
92
118
|
return (0, _fetchData.default)('auth/enable-2fa-email');
|
|
93
119
|
case 9:
|
|
94
|
-
|
|
120
|
+
_context2.next = 14;
|
|
95
121
|
break;
|
|
96
122
|
case 11:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.log('π ~ error while sending email:',
|
|
123
|
+
_context2.prev = 11;
|
|
124
|
+
_context2.t0 = _context2["catch"](6);
|
|
125
|
+
console.log('π ~ error while sending email:', _context2.t0);
|
|
100
126
|
case 14:
|
|
101
|
-
|
|
127
|
+
_context2.next = 25;
|
|
102
128
|
break;
|
|
103
129
|
case 16:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
console.log('π ~ file: enable-2fa-flow.js:60 ~ error:',
|
|
107
|
-
if (!(
|
|
108
|
-
|
|
130
|
+
_context2.prev = 16;
|
|
131
|
+
_context2.t1 = _context2["catch"](2);
|
|
132
|
+
console.log('π ~ file: enable-2fa-flow.js:60 ~ error:', _context2.t1);
|
|
133
|
+
if (!(_context2.t1.code === 'auth/invalid-verification-code')) {
|
|
134
|
+
_context2.next = 24;
|
|
109
135
|
break;
|
|
110
136
|
}
|
|
111
137
|
setpopupError({
|
|
112
138
|
popup: 'enter2fa',
|
|
113
139
|
message: 'Thatβs not the right 2FA code. Try again'
|
|
114
140
|
});
|
|
115
|
-
return
|
|
141
|
+
return _context2.abrupt("return", {
|
|
116
142
|
otpInput: 'Invalid code'
|
|
117
143
|
});
|
|
118
144
|
case 24:
|
|
119
|
-
if (
|
|
145
|
+
if (_context2.t1.code === 'auth/requires-recent-login') {
|
|
120
146
|
onRequiresRecentLoginError && onRequiresRecentLoginError();
|
|
121
147
|
} else {
|
|
122
148
|
setpopupError({
|
|
123
149
|
popup: 'enter2fa',
|
|
124
|
-
message: "".concat(
|
|
150
|
+
message: "".concat(_context2.t1 !== null && _context2.t1 !== void 0 && _context2.t1.message ? _context2.t1 === null || _context2.t1 === void 0 ? void 0 : _context2.t1.message : 'Something went wrong. Try again?')
|
|
125
151
|
});
|
|
126
152
|
}
|
|
127
153
|
case 25:
|
|
128
154
|
case "end":
|
|
129
|
-
return
|
|
155
|
+
return _context2.stop();
|
|
130
156
|
}
|
|
131
|
-
},
|
|
157
|
+
}, _callee2, null, [[2, 16], [6, 11]]);
|
|
132
158
|
}));
|
|
133
159
|
return function onSubmit(_x) {
|
|
134
|
-
return
|
|
160
|
+
return _ref3.apply(this, arguments);
|
|
135
161
|
};
|
|
136
162
|
}();
|
|
137
163
|
var onBackButtonClick = function onBackButtonClick(stepController, prevStepIndex) {
|
|
@@ -97,31 +97,27 @@ var Main2FAFlow = function Main2FAFlow(_ref) {
|
|
|
97
97
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
98
98
|
while (1) switch (_context.prev = _context.next) {
|
|
99
99
|
case 0:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
_context.prev = 1;
|
|
105
|
-
_context.next = 4;
|
|
100
|
+
_context.prev = 0;
|
|
101
|
+
_context.next = 3;
|
|
106
102
|
return generateTotpSecret(user);
|
|
107
|
-
case
|
|
103
|
+
case 3:
|
|
108
104
|
response = _context.sent;
|
|
109
105
|
console.log('π ~ response:', response);
|
|
110
106
|
settotpData(response);
|
|
111
|
-
_context.next =
|
|
107
|
+
_context.next = 11;
|
|
112
108
|
break;
|
|
113
|
-
case
|
|
114
|
-
_context.prev =
|
|
115
|
-
_context.t0 = _context["catch"](
|
|
109
|
+
case 8:
|
|
110
|
+
_context.prev = 8;
|
|
111
|
+
_context.t0 = _context["catch"](0);
|
|
116
112
|
if (_context.t0.code === 'auth/requires-recent-login' || _context.t0.code === 'auth/unsupported-first-factor') {
|
|
117
113
|
setisLoginRequired(true);
|
|
118
114
|
// onRequiresRecentLoginError && onRequiresRecentLoginError()
|
|
119
115
|
}
|
|
120
|
-
case
|
|
116
|
+
case 11:
|
|
121
117
|
case "end":
|
|
122
118
|
return _context.stop();
|
|
123
119
|
}
|
|
124
|
-
}, _callee, null, [[
|
|
120
|
+
}, _callee, null, [[0, 8]]);
|
|
125
121
|
}));
|
|
126
122
|
return function generateTotp() {
|
|
127
123
|
return _ref2.apply(this, arguments);
|
|
@@ -198,7 +194,8 @@ var Main2FAFlow = function Main2FAFlow(_ref) {
|
|
|
198
194
|
margin: 0
|
|
199
195
|
},
|
|
200
196
|
handleChange: function handleChange(value) {
|
|
201
|
-
if
|
|
197
|
+
//log in again is only if you try to set up 2fa, not disable it
|
|
198
|
+
if (isLoginRequired && value === 'disabled') {
|
|
202
199
|
setIsFlowOpen({
|
|
203
200
|
requiresRecentLogin: true,
|
|
204
201
|
enable2fa: false,
|
package/dist/context/Auth.js
CHANGED
|
@@ -153,6 +153,20 @@ var Auth = /*#__PURE__*/function () {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "refreshIdToken",
|
|
158
|
+
value: function refreshIdToken() {
|
|
159
|
+
return new Promise(function (resolve, reject) {
|
|
160
|
+
var user = _firebaseConfig.auth.currentUser;
|
|
161
|
+
if (!user) reject('User not available');
|
|
162
|
+
user.getIdToken(true).then(function (idToken) {
|
|
163
|
+
console.log('Token refreshed');
|
|
164
|
+
resolve(idToken);
|
|
165
|
+
}).catch(function (error) {
|
|
166
|
+
reject(error);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
156
170
|
}, {
|
|
157
171
|
key: "signInWithToken",
|
|
158
172
|
value: function signInWithToken(token) {
|
|
@@ -1011,7 +1011,8 @@ var AuthProviderClass = /*#__PURE__*/function (_Component) {
|
|
|
1011
1011
|
updateFirebaseUser: _Auth.default.updateFirebaseUser,
|
|
1012
1012
|
handleResetPassword: this.handleResetPassword,
|
|
1013
1013
|
handleVerifyEmail: this.handleVerifyEmail,
|
|
1014
|
-
setUser: this.setUser
|
|
1014
|
+
setUser: this.setUser,
|
|
1015
|
+
refreshIdToken: _Auth.default.refreshIdToken
|
|
1015
1016
|
})
|
|
1016
1017
|
}, children);
|
|
1017
1018
|
}
|