Skip to content

Commit 30929e4

Browse files
committed
fix: connect-and-sign auth mode is not working
1 parent 970d100 commit 30929e4

File tree

9 files changed

+26
-10
lines changed

9 files changed

+26
-10
lines changed

packages/modal/src/modalManager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,11 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
528528
this.subscribeToConnectorEvents(connector);
529529
const initialChain = this.getInitialChainIdForConnector(connector);
530530
const autoConnect = super.checkIfAutoConnect(connector);
531-
await connector.init({ autoConnect, chainId: initialChain.chainId });
531+
await connector.init({
532+
autoConnect,
533+
chainId: initialChain.chainId,
534+
getIdentityToken: this.options.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN,
535+
});
532536

533537
// note: not adding cachedWallet to modal if it is external wallet.
534538
// adding it later if no in-app wallets are available.
@@ -574,7 +578,11 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
574578
try {
575579
this.subscribeToConnectorEvents(connector);
576580
const initialChain = this.getInitialChainIdForConnector(connector);
577-
await connector.init({ autoConnect: this.cachedConnector === connectorName, chainId: initialChain.chainId });
581+
await connector.init({
582+
autoConnect: this.cachedConnector === connectorName,
583+
chainId: initialChain.chainId,
584+
getIdentityToken: this.options.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN,
585+
});
578586
} catch (error) {
579587
log.error(error, "error while initializing connector", connectorName);
580588
}

packages/no-modal/src/base/connector/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export interface ConnectorInitOptions {
3838
* The chainId to connect to
3939
*/
4040
chainId: string;
41+
/**
42+
* Whether to get the identity token
43+
*/
44+
getIdentityToken?: boolean;
4145
}
4246

4347
export type CONNECTOR_STATUS_TYPE = (typeof CONNECTOR_STATUS)[keyof typeof CONNECTOR_STATUS];

packages/no-modal/src/connectors/auth-connector/authConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class AuthConnector extends BaseConnector<AuthLoginParams> {
188188
// connect only if it is redirect result or if connect (connector is cached/already connected in same session) is true
189189
if (sessionId && (options.autoConnect || isRedirectResult)) {
190190
this.rehydrated = true;
191-
await this.connect({ chainId: options.chainId, getIdentityToken: false });
191+
await this.connect({ chainId: options.chainId, getIdentityToken: options.getIdentityToken });
192192
} else if (!sessionId && options.autoConnect) {
193193
// if here, this means that the connector is cached but the sessionId is not available.
194194
// this can happen if the sessionId has expired.

packages/no-modal/src/connectors/coinbase-connector/coinbaseConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CoinbaseConnector extends BaseEvmConnector<void> {
8282
try {
8383
if (options.autoConnect) {
8484
this.rehydrated = true;
85-
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: false });
85+
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: options.getIdentityToken });
8686
// the connect function could fail silently as well.
8787
if (!provider) {
8888
this.rehydrated = false;

packages/no-modal/src/connectors/injected-evm-connector/injectedEvmConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class InjectedEvmConnector extends BaseEvmConnector<void> {
7171
log.debug(`initializing ${this.name} injected connector`);
7272
if (options.autoConnect) {
7373
this.rehydrated = true;
74-
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: false });
74+
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: options.getIdentityToken });
7575
if (!provider) {
7676
this.rehydrated = false;
7777
throw WalletLoginError.connectionError("Failed to rehydrate.");

packages/no-modal/src/connectors/injected-solana-connector/walletStandardConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class WalletStandardConnector extends BaseSolanaConnector<void> {
8181
log.debug("initializing solana injected connector");
8282
if (options.autoConnect) {
8383
this.rehydrated = true;
84-
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: false });
84+
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: options.getIdentityToken });
8585
if (!provider) {
8686
this.rehydrated = false;
8787
throw WalletLoginError.connectionError("Failed to rehydrate.");

packages/no-modal/src/connectors/metamask-connector/metamaskConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class MetaMaskConnector extends BaseEvmConnector<void> {
105105
try {
106106
if (options.autoConnect) {
107107
this.rehydrated = true;
108-
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: false });
108+
const provider = await this.connect({ chainId: options.chainId, getIdentityToken: options.getIdentityToken });
109109
if (!provider) {
110110
this.rehydrated = false;
111111
throw WalletLoginError.connectionError("Failed to rehydrate.");

packages/no-modal/src/connectors/wallet-connect-v2-connector/walletConnectV2Connector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class WalletConnectV2Connector extends BaseConnector<void> {
140140
if (this.connected) {
141141
this.rehydrated = true;
142142
try {
143-
await this.onConnectHandler({ chain: chainConfig, getIdentityToken: false });
143+
await this.onConnectHandler({ chain: chainConfig, getIdentityToken: options.getIdentityToken });
144144
} catch (error) {
145145
log.error("wallet auto connect", error);
146146
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error as Web3AuthError);
@@ -196,7 +196,7 @@ class WalletConnectV2Connector extends BaseConnector<void> {
196196

197197
// if already connected
198198
if (this.connected) {
199-
await this.onConnectHandler({ chain: chainConfig, getIdentityToken: false });
199+
await this.onConnectHandler({ chain: chainConfig, getIdentityToken });
200200
return this.provider;
201201
}
202202

packages/no-modal/src/noModal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,11 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
730730
try {
731731
const initialChain = this.getInitialChainIdForConnector(connector);
732732
const autoConnect = this.checkIfAutoConnect(connector);
733-
await connector.init({ autoConnect, chainId: initialChain.chainId });
733+
await connector.init({
734+
autoConnect,
735+
chainId: initialChain.chainId,
736+
getIdentityToken: this.coreOptions.initialAuthenticationMode === CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN,
737+
});
734738
} catch (e) {
735739
log.error(e, connector.name);
736740
}

0 commit comments

Comments
 (0)