@dynamic-labs/sdk-react-core 2.3.9 → 2.3.10
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 +7 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +13 -13
- package/src/lib/data/api/oauth/oauth.cjs +0 -18
- package/src/lib/data/api/oauth/oauth.js +1 -18
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +23 -75
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +26 -78
- package/src/lib/views/LoginView/LoginViewSection/LoginViewSection.cjs +20 -16
- package/src/lib/views/LoginView/LoginViewSection/LoginViewSection.js +20 -16
- package/src/lib/views/LoginView/sections/ToggleableSection/ToggleableSection.d.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [2.3.10](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.9...v2.3.10) (2024-08-15)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* twitter should no longer rely polling for oauth flow ([#6606](https://github.com/dynamic-labs/DynamicAuth/issues/6606)) ([38906ab](https://github.com/dynamic-labs/DynamicAuth/commit/38906ab02b41fd02d7993e229072290d046dbc0e))
|
|
8
|
+
|
|
2
9
|
### [2.3.9](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.8...v2.3.9) (2024-08-13)
|
|
3
10
|
|
|
4
11
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"react-i18next": "13.5.0",
|
|
18
18
|
"yup": "0.32.11",
|
|
19
19
|
"react-international-phone": "4.2.5",
|
|
20
|
-
"@dynamic-labs/iconic": "2.3.
|
|
21
|
-
"@dynamic-labs/logger": "2.3.
|
|
22
|
-
"@dynamic-labs/multi-wallet": "2.3.
|
|
23
|
-
"@dynamic-labs/rpc-provider-ethereum": "2.3.
|
|
24
|
-
"@dynamic-labs/rpc-provider-solana": "2.3.
|
|
25
|
-
"@dynamic-labs/rpc-providers": "2.3.
|
|
26
|
-
"@dynamic-labs/store": "2.3.
|
|
27
|
-
"@dynamic-labs/types": "2.3.
|
|
28
|
-
"@dynamic-labs/utils": "2.3.
|
|
29
|
-
"@dynamic-labs/viem-utils": "2.3.
|
|
30
|
-
"@dynamic-labs/wallet-book": "2.3.
|
|
31
|
-
"@dynamic-labs/wallet-connector-core": "2.3.
|
|
20
|
+
"@dynamic-labs/iconic": "2.3.10",
|
|
21
|
+
"@dynamic-labs/logger": "2.3.10",
|
|
22
|
+
"@dynamic-labs/multi-wallet": "2.3.10",
|
|
23
|
+
"@dynamic-labs/rpc-provider-ethereum": "2.3.10",
|
|
24
|
+
"@dynamic-labs/rpc-provider-solana": "2.3.10",
|
|
25
|
+
"@dynamic-labs/rpc-providers": "2.3.10",
|
|
26
|
+
"@dynamic-labs/store": "2.3.10",
|
|
27
|
+
"@dynamic-labs/types": "2.3.10",
|
|
28
|
+
"@dynamic-labs/utils": "2.3.10",
|
|
29
|
+
"@dynamic-labs/viem-utils": "2.3.10",
|
|
30
|
+
"@dynamic-labs/wallet-book": "2.3.10",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "2.3.10",
|
|
32
32
|
"eventemitter3": "5.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -95,23 +95,6 @@ const signInOAuth = (environmentId_2, providerType_2, _c) => _tslib.__awaiter(vo
|
|
|
95
95
|
return undefined;
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
|
-
const getOAuthResult = (environmentId_3, providerType_3, _e) => _tslib.__awaiter(void 0, [environmentId_3, providerType_3, _e], void 0, function* (environmentId, providerType, { state }) {
|
|
99
|
-
const oauthResultRequest = {
|
|
100
|
-
state,
|
|
101
|
-
};
|
|
102
|
-
try {
|
|
103
|
-
const result = yield api.sdkApi().oauthResult({
|
|
104
|
-
environmentId,
|
|
105
|
-
oauthResultRequest,
|
|
106
|
-
providerType,
|
|
107
|
-
});
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
catch (e) {
|
|
111
|
-
logger.logger.error(e);
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
98
|
const farcasterSignIn = (environmentId, farcasterSignInRequest) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
116
99
|
try {
|
|
117
100
|
const response = yield api.sdkApi().farcasterSignIn({
|
|
@@ -151,7 +134,6 @@ const farcasterVerify = (farcasterVerifyRequest) => _tslib.__awaiter(void 0, voi
|
|
|
151
134
|
|
|
152
135
|
exports.farcasterSignIn = farcasterSignIn;
|
|
153
136
|
exports.farcasterVerify = farcasterVerify;
|
|
154
|
-
exports.getOAuthResult = getOAuthResult;
|
|
155
137
|
exports.signInOAuth = signInOAuth;
|
|
156
138
|
exports.unlinkOAuth = unlinkOAuth;
|
|
157
139
|
exports.verifyOAuth = verifyOAuth;
|
|
@@ -91,23 +91,6 @@ const signInOAuth = (environmentId_2, providerType_2, _c) => __awaiter(void 0, [
|
|
|
91
91
|
return undefined;
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
-
const getOAuthResult = (environmentId_3, providerType_3, _e) => __awaiter(void 0, [environmentId_3, providerType_3, _e], void 0, function* (environmentId, providerType, { state }) {
|
|
95
|
-
const oauthResultRequest = {
|
|
96
|
-
state,
|
|
97
|
-
};
|
|
98
|
-
try {
|
|
99
|
-
const result = yield sdkApi().oauthResult({
|
|
100
|
-
environmentId,
|
|
101
|
-
oauthResultRequest,
|
|
102
|
-
providerType,
|
|
103
|
-
});
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
logger.error(e);
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
94
|
const farcasterSignIn = (environmentId, farcasterSignInRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
95
|
try {
|
|
113
96
|
const response = yield sdkApi().farcasterSignIn({
|
|
@@ -145,4 +128,4 @@ const farcasterVerify = (farcasterVerifyRequest) => __awaiter(void 0, void 0, vo
|
|
|
145
128
|
}
|
|
146
129
|
});
|
|
147
130
|
|
|
148
|
-
export { farcasterSignIn, farcasterVerify,
|
|
131
|
+
export { farcasterSignIn, farcasterVerify, signInOAuth, unlinkOAuth, verifyOAuth };
|
|
@@ -103,7 +103,6 @@ const socialProviders = [
|
|
|
103
103
|
// pkce params are only required for twitter and break if added for other providers, like google
|
|
104
104
|
// so we should only add provider that support pkce to this list
|
|
105
105
|
const providersRequiringPkce = ['twitter', 'github'];
|
|
106
|
-
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
107
106
|
// Hook to handle common social auth logic (for social linking and social sign in)
|
|
108
107
|
const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }) => {
|
|
109
108
|
const { environmentId, setShowAuthFlow, projectSettings, consumeNonce, redirectUrl, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
@@ -115,7 +114,6 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
115
114
|
const [error, setError] = React.useState();
|
|
116
115
|
const providersWaitingOauthMessage = React.useRef({});
|
|
117
116
|
const authWindowInterval = React.useRef();
|
|
118
|
-
const shouldPool = React.useRef(false);
|
|
119
117
|
const clearError = () => {
|
|
120
118
|
setError(undefined);
|
|
121
119
|
setContextError(undefined);
|
|
@@ -138,26 +136,6 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
138
136
|
setErrorMessage(code);
|
|
139
137
|
onFailed(provider, { error }, options);
|
|
140
138
|
};
|
|
141
|
-
const poolOauthResult = (provider, state) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
-
if (!shouldPool.current) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const result = yield oauth.getOAuthResult(environmentId, provider, {
|
|
146
|
-
state,
|
|
147
|
-
});
|
|
148
|
-
if ((result === null || result === void 0 ? void 0 : result.status) !== sdkApiCore.OauthResultStatus.Completed) {
|
|
149
|
-
setTimeout(() => poolOauthResult(provider, state), 1000);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
shouldPool.current = false;
|
|
153
|
-
const authMessage = {
|
|
154
|
-
code: result === null || result === void 0 ? void 0 : result.code,
|
|
155
|
-
error: result === null || result === void 0 ? void 0 : result.error,
|
|
156
|
-
provider,
|
|
157
|
-
type: 'authorization_response',
|
|
158
|
-
};
|
|
159
|
-
window.postMessage(authMessage, '*');
|
|
160
|
-
});
|
|
161
139
|
const checkValidProvider = (provider, authMode) => {
|
|
162
140
|
if (!provider) {
|
|
163
141
|
handleError(provider, types.SocialOAuthErrorCode.NO_PROVIDER, 'Provider is required', { raiseAuthFailure: authMode === 'signin' });
|
|
@@ -230,17 +208,15 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
230
208
|
return;
|
|
231
209
|
}
|
|
232
210
|
let expectedOrigin = window.location.origin;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
211
|
+
try {
|
|
212
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
213
|
+
expectedOrigin = redirectUri.origin;
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
logger.logger.error('Failed to parse social provider redirect url', {
|
|
217
|
+
error: e,
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
244
220
|
}
|
|
245
221
|
if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
|
|
246
222
|
logger.logger.debug('Origin check message received. Sending response now.', {
|
|
@@ -276,8 +252,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
276
252
|
// check that the state we receive from message is the same state we calculated earlier
|
|
277
253
|
// this could be an attack
|
|
278
254
|
// this state check is used only by providers with an open window opener reference (eg, not twitter)
|
|
279
|
-
if (
|
|
280
|
-
state !== authState) {
|
|
255
|
+
if (state !== authState) {
|
|
281
256
|
handleError(provider, types.SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: Invalid random state`, { raiseAuthFailure: authMode === 'signin' });
|
|
282
257
|
return;
|
|
283
258
|
}
|
|
@@ -328,48 +303,21 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
328
303
|
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
329
304
|
}
|
|
330
305
|
authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
clearInterval(authWindowInterval.current);
|
|
339
|
-
setIsProcessing(false);
|
|
340
|
-
// user didn't complete oauth
|
|
341
|
-
if ((_a = providersWaitingOauthMessage.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
342
|
-
onFailed(provider, 'user-cancelled');
|
|
343
|
-
}
|
|
344
|
-
}, 2000);
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
// For provider that don't support window.opener, we need to use a timeout to pool the oauth result
|
|
348
|
-
// If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
|
|
349
|
-
// and we'll clear all states/listeners
|
|
350
|
-
// start pooling oauth result
|
|
351
|
-
shouldPool.current = true;
|
|
352
|
-
poolOauthResult(provider, state);
|
|
353
|
-
// if this is mobile, set a longer timeout to allow the user to login to the provider in the browser
|
|
354
|
-
let authWindowTimeout = sessionTimeout;
|
|
355
|
-
if (utils.isMobile()) {
|
|
356
|
-
authWindowTimeout = authWindowTimeout * 3;
|
|
306
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
307
|
+
authWindowInterval.current = setInterval(() => {
|
|
308
|
+
var _a;
|
|
309
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
310
|
+
return;
|
|
357
311
|
}
|
|
358
|
-
authWindowInterval.current
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
clearInterval(authWindowInterval.current);
|
|
367
|
-
setIsProcessing(false);
|
|
368
|
-
onSettled === null || onSettled === void 0 ? void 0 : onSettled();
|
|
369
|
-
}), authWindowTimeout);
|
|
370
|
-
}
|
|
312
|
+
clearInterval(authWindowInterval.current);
|
|
313
|
+
setIsProcessing(false);
|
|
314
|
+
// user didn't complete oauth
|
|
315
|
+
if ((_a = providersWaitingOauthMessage.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
316
|
+
onFailed(provider, 'user-cancelled');
|
|
317
|
+
}
|
|
318
|
+
}, 2000);
|
|
371
319
|
});
|
|
372
|
-
const connectWithFarcaster = (authMode_1,
|
|
320
|
+
const connectWithFarcaster = (authMode_1, _f) => _tslib.__awaiter(void 0, [authMode_1, _f], void 0, function* (authMode, { captchaToken }) {
|
|
373
321
|
const dynamicNonce = consumeNonce();
|
|
374
322
|
const domain = utils.PlatformService.getHost();
|
|
375
323
|
const data = yield farcaster.connect({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
3
|
import { useState, useRef } from 'react';
|
|
4
|
-
import { ProviderEnum
|
|
4
|
+
import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
5
|
import { SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
6
|
-
import {
|
|
6
|
+
import { PlatformService, isMobile, SocialAccountAlreadyExistsError } from '@dynamic-labs/utils';
|
|
7
7
|
import '../../../context/DynamicContext/DynamicContext.js';
|
|
8
8
|
import { logger } from '../../../shared/logger.js';
|
|
9
9
|
import '@dynamic-labs/iconic';
|
|
@@ -31,7 +31,7 @@ import 'viem';
|
|
|
31
31
|
import 'viem/chains';
|
|
32
32
|
import '../../../config/ApiEndpoint.js';
|
|
33
33
|
import '@dynamic-labs/store';
|
|
34
|
-
import {
|
|
34
|
+
import { signInOAuth, verifyOAuth, farcasterSignIn, farcasterVerify } from '../../../data/api/oauth/oauth.js';
|
|
35
35
|
import '../../../locale/locale.js';
|
|
36
36
|
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
37
37
|
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
@@ -99,7 +99,6 @@ const socialProviders = [
|
|
|
99
99
|
// pkce params are only required for twitter and break if added for other providers, like google
|
|
100
100
|
// so we should only add provider that support pkce to this list
|
|
101
101
|
const providersRequiringPkce = ['twitter', 'github'];
|
|
102
|
-
const providersWithoutWindowOpenerRefence = ['twitter'];
|
|
103
102
|
// Hook to handle common social auth logic (for social linking and social sign in)
|
|
104
103
|
const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }) => {
|
|
105
104
|
const { environmentId, setShowAuthFlow, projectSettings, consumeNonce, redirectUrl, } = useInternalDynamicContext();
|
|
@@ -111,7 +110,6 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
111
110
|
const [error, setError] = useState();
|
|
112
111
|
const providersWaitingOauthMessage = useRef({});
|
|
113
112
|
const authWindowInterval = useRef();
|
|
114
|
-
const shouldPool = useRef(false);
|
|
115
113
|
const clearError = () => {
|
|
116
114
|
setError(undefined);
|
|
117
115
|
setContextError(undefined);
|
|
@@ -134,26 +132,6 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
134
132
|
setErrorMessage(code);
|
|
135
133
|
onFailed(provider, { error }, options);
|
|
136
134
|
};
|
|
137
|
-
const poolOauthResult = (provider, state) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
if (!shouldPool.current) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const result = yield getOAuthResult(environmentId, provider, {
|
|
142
|
-
state,
|
|
143
|
-
});
|
|
144
|
-
if ((result === null || result === void 0 ? void 0 : result.status) !== OauthResultStatus.Completed) {
|
|
145
|
-
setTimeout(() => poolOauthResult(provider, state), 1000);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
shouldPool.current = false;
|
|
149
|
-
const authMessage = {
|
|
150
|
-
code: result === null || result === void 0 ? void 0 : result.code,
|
|
151
|
-
error: result === null || result === void 0 ? void 0 : result.error,
|
|
152
|
-
provider,
|
|
153
|
-
type: 'authorization_response',
|
|
154
|
-
};
|
|
155
|
-
window.postMessage(authMessage, '*');
|
|
156
|
-
});
|
|
157
135
|
const checkValidProvider = (provider, authMode) => {
|
|
158
136
|
if (!provider) {
|
|
159
137
|
handleError(provider, SocialOAuthErrorCode.NO_PROVIDER, 'Provider is required', { raiseAuthFailure: authMode === 'signin' });
|
|
@@ -226,17 +204,15 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
226
204
|
return;
|
|
227
205
|
}
|
|
228
206
|
let expectedOrigin = window.location.origin;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
207
|
+
try {
|
|
208
|
+
const redirectUri = new URL(apiProvider.redirectUrl);
|
|
209
|
+
expectedOrigin = redirectUri.origin;
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
logger.error('Failed to parse social provider redirect url', {
|
|
213
|
+
error: e,
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
240
216
|
}
|
|
241
217
|
if ((message === null || message === void 0 ? void 0 : message.type) === 'origin_check' && authWindow) {
|
|
242
218
|
logger.debug('Origin check message received. Sending response now.', {
|
|
@@ -272,8 +248,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
272
248
|
// check that the state we receive from message is the same state we calculated earlier
|
|
273
249
|
// this could be an attack
|
|
274
250
|
// this state check is used only by providers with an open window opener reference (eg, not twitter)
|
|
275
|
-
if (
|
|
276
|
-
state !== authState) {
|
|
251
|
+
if (state !== authState) {
|
|
277
252
|
handleError(provider, SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: Invalid random state`, { raiseAuthFailure: authMode === 'signin' });
|
|
278
253
|
return;
|
|
279
254
|
}
|
|
@@ -324,48 +299,21 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
|
|
|
324
299
|
oauthLoginUrl = `${oauthLoginUrl}&${pkceParams}`;
|
|
325
300
|
}
|
|
326
301
|
authWindow === null || authWindow === void 0 ? void 0 : authWindow.location.assign(oauthLoginUrl);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
clearInterval(authWindowInterval.current);
|
|
335
|
-
setIsProcessing(false);
|
|
336
|
-
// user didn't complete oauth
|
|
337
|
-
if ((_a = providersWaitingOauthMessage.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
338
|
-
onFailed(provider, 'user-cancelled');
|
|
339
|
-
}
|
|
340
|
-
}, 2000);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
// For provider that don't support window.opener, we need to use a timeout to pool the oauth result
|
|
344
|
-
// If we don't get a valid result in {async sessionTimeout} ms, we'll assume the user closed the window
|
|
345
|
-
// and we'll clear all states/listeners
|
|
346
|
-
// start pooling oauth result
|
|
347
|
-
shouldPool.current = true;
|
|
348
|
-
poolOauthResult(provider, state);
|
|
349
|
-
// if this is mobile, set a longer timeout to allow the user to login to the provider in the browser
|
|
350
|
-
let authWindowTimeout = sessionTimeout;
|
|
351
|
-
if (isMobile()) {
|
|
352
|
-
authWindowTimeout = authWindowTimeout * 3;
|
|
302
|
+
// For provider that support window.opener, we need to clear all states/listeners when the window is closed
|
|
303
|
+
authWindowInterval.current = setInterval(() => {
|
|
304
|
+
var _a;
|
|
305
|
+
if (!(authWindow === null || authWindow === void 0 ? void 0 : authWindow.closed)) {
|
|
306
|
+
return;
|
|
353
307
|
}
|
|
354
|
-
authWindowInterval.current
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
clearInterval(authWindowInterval.current);
|
|
363
|
-
setIsProcessing(false);
|
|
364
|
-
onSettled === null || onSettled === void 0 ? void 0 : onSettled();
|
|
365
|
-
}), authWindowTimeout);
|
|
366
|
-
}
|
|
308
|
+
clearInterval(authWindowInterval.current);
|
|
309
|
+
setIsProcessing(false);
|
|
310
|
+
// user didn't complete oauth
|
|
311
|
+
if ((_a = providersWaitingOauthMessage.current) === null || _a === void 0 ? void 0 : _a[provider]) {
|
|
312
|
+
onFailed(provider, 'user-cancelled');
|
|
313
|
+
}
|
|
314
|
+
}, 2000);
|
|
367
315
|
});
|
|
368
|
-
const connectWithFarcaster = (authMode_1,
|
|
316
|
+
const connectWithFarcaster = (authMode_1, _f) => __awaiter(void 0, [authMode_1, _f], void 0, function* (authMode, { captchaToken }) {
|
|
369
317
|
const dynamicNonce = consumeNonce();
|
|
370
318
|
const domain = PlatformService.getHost();
|
|
371
319
|
const data = yield connect({
|
|
@@ -98,22 +98,26 @@ const LoginViewSection = ({ viewSection, index, walletCount, gotToWalletList, })
|
|
|
98
98
|
case sdkApiCore.SdkViewSectionType.Phone:
|
|
99
99
|
return (jsxRuntime.jsx(PhoneNumberSignInSection.PhoneNumberSignInSection, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading }));
|
|
100
100
|
case sdkApiCore.SdkViewSectionType.EmailAndPhone:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
// eslint-disable-next-line no-case-declarations
|
|
102
|
+
const sections = [
|
|
103
|
+
{
|
|
104
|
+
button: t('dyn_login.email_or_phone.use_phone'),
|
|
105
|
+
buttonCopyKey: 'dyn_login.email_or_phone.use_phone',
|
|
106
|
+
component: (jsxRuntime.jsx(LoginEmailForm.LoginEmailForm, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading })),
|
|
107
|
+
label: t('dyn_login.email_or_phone.prefer_phone'),
|
|
108
|
+
labelCopyKey: 'dyn_login.email_or_phone.prefer_phone',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
button: t('dyn_login.email_or_phone.use_email'),
|
|
112
|
+
buttonCopyKey: 'dyn_login.email_or_phone.use_email',
|
|
113
|
+
component: (jsxRuntime.jsx(PhoneNumberSignInSection.PhoneNumberSignInSection, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading })),
|
|
114
|
+
label: t('dyn_login.email_or_phone.prefer_email'),
|
|
115
|
+
labelCopyKey: 'dyn_login.email_or_phone.prefer_email',
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
if (viewSection.defaultItem === 'phone')
|
|
119
|
+
sections.reverse();
|
|
120
|
+
return jsxRuntime.jsx(ToggleableSection.ToggleableSection, { sections: sections });
|
|
117
121
|
case sdkApiCore.SdkViewSectionType.Wallet:
|
|
118
122
|
return (jsxRuntime.jsx(WalletSignInSection.WalletSignInSection, { numberOfItensToShow: viewSection.numOfItemsToDisplay || 0, onSubmit: () => {
|
|
119
123
|
// this view is just to show the back button
|
|
@@ -94,22 +94,26 @@ const LoginViewSection = ({ viewSection, index, walletCount, gotToWalletList, })
|
|
|
94
94
|
case SdkViewSectionType.Phone:
|
|
95
95
|
return (jsx(PhoneNumberSignInSection, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading }));
|
|
96
96
|
case SdkViewSectionType.EmailAndPhone:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
// eslint-disable-next-line no-case-declarations
|
|
98
|
+
const sections = [
|
|
99
|
+
{
|
|
100
|
+
button: t('dyn_login.email_or_phone.use_phone'),
|
|
101
|
+
buttonCopyKey: 'dyn_login.email_or_phone.use_phone',
|
|
102
|
+
component: (jsx(LoginEmailForm, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading })),
|
|
103
|
+
label: t('dyn_login.email_or_phone.prefer_phone'),
|
|
104
|
+
labelCopyKey: 'dyn_login.email_or_phone.prefer_phone',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
button: t('dyn_login.email_or_phone.use_email'),
|
|
108
|
+
buttonCopyKey: 'dyn_login.email_or_phone.use_email',
|
|
109
|
+
component: (jsx(PhoneNumberSignInSection, { onSubmit: () => setIsLoading(true), onSubmitError: () => setIsLoading(false), isLoading: isLoading })),
|
|
110
|
+
label: t('dyn_login.email_or_phone.prefer_email'),
|
|
111
|
+
labelCopyKey: 'dyn_login.email_or_phone.prefer_email',
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
if (viewSection.defaultItem === 'phone')
|
|
115
|
+
sections.reverse();
|
|
116
|
+
return jsx(ToggleableSection, { sections: sections });
|
|
113
117
|
case SdkViewSectionType.Wallet:
|
|
114
118
|
return (jsx(WalletSignInSection, { numberOfItensToShow: viewSection.numOfItemsToDisplay || 0, onSubmit: () => {
|
|
115
119
|
// this view is just to show the back button
|
|
@@ -6,8 +6,7 @@ export type Section = {
|
|
|
6
6
|
buttonCopyKey?: string;
|
|
7
7
|
labelCopyKey?: string;
|
|
8
8
|
};
|
|
9
|
-
type ToggleableSectionProps = {
|
|
9
|
+
export type ToggleableSectionProps = {
|
|
10
10
|
sections: [Section, Section];
|
|
11
11
|
};
|
|
12
12
|
export declare const ToggleableSection: FC<ToggleableSectionProps>;
|
|
13
|
-
export {};
|