Skip to content

Commit c5ed64d

Browse files
committed
updates sdk params + rename functions
1 parent 6fdd8a1 commit c5ed64d

File tree

19 files changed

+92
-61
lines changed

19 files changed

+92
-61
lines changed

demo/nextjs-ssr-app/components/Main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Main = () => {
2828
const { showCheckout, loading: isCheckoutLoading, error: checkoutError } = useCheckout();
2929
const { showWalletConnectScanner, loading: isWalletConnectScannerLoading, error: walletConnectScannerError } = useWalletConnectScanner();
3030
const { showWalletUI, loading: isWalletUILoading, error: walletUIError } = useWalletUI();
31-
const { token, loading: isUserTokenLoading, error: userTokenError, authenticateUser } = useIdentityToken();
31+
const { token, loading: isUserTokenLoading, error: userTokenError, getIdentityToken } = useIdentityToken();
3232

3333
console.log("isConnected", isConnected);
3434

@@ -56,7 +56,7 @@ const Main = () => {
5656
{isUserTokenLoading ? (
5757
<p>Authenticating...</p>
5858
) : (
59-
<button onClick={() => authenticateUser()} className="card">
59+
<button onClick={() => getIdentityToken()} className="card">
6060
Authenticate User
6161
</button>
6262
)}

demo/react-app-no-modal/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ function App() {
4444
setProvider(web3authProvider);
4545
};
4646

47-
const authenticateUser = async () => {
47+
const getIdentityToken = async () => {
4848
if (!web3auth) {
4949
uiConsole("web3auth not initialized yet");
5050
return;
5151
}
52-
const idToken = await web3auth.authenticateUser();
52+
const idToken = await web3auth.getIdentityToken();
5353
uiConsole(idToken);
5454
};
5555

@@ -156,7 +156,7 @@ function App() {
156156
</button>
157157
</div>
158158
<div>
159-
<button onClick={authenticateUser} className="card">
159+
<button onClick={getIdentityToken} className="card">
160160
Get ID Token
161161
</button>
162162
</div>

demo/vue-app-new/src/components/AppDashboard.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const { switchChain } = useWeb3AuthSwitchChain();
4747
const { showWalletUI, loading: showWalletUILoading } = useWalletUI();
4848
const { showWalletConnectScanner, loading: showWalletConnectScannerLoading } = useWalletConnectScanner();
4949
const { showCheckout, loading: showCheckoutLoading } = useCheckout();
50-
const { authenticateUser, loading: authenticateUserLoading } = useIdentityToken();
50+
const { getIdentityToken, loading: getIdentityTokenLoading } = useIdentityToken();
5151
const { status, address } = useAccount();
5252
const { signTypedDataAsync } = useSignTypedData();
5353
const { signMessageAsync } = useSignMessage();
@@ -164,8 +164,8 @@ const onGetUserInfo = async () => {
164164
printToConsole("User Info", userInfo.value);
165165
};
166166
167-
const onAuthenticateUser = async () => {
168-
const idToken = await authenticateUser();
167+
const ongetIdentityToken = async () => {
168+
const idToken = await getIdentityToken();
169169
printToConsole("id token", idToken);
170170
};
171171
@@ -451,7 +451,7 @@ const onSwitchChainNamespace = async () => {
451451
<Button block size="xs" pill class="mb-2" @click="onSignPersonalMsg">
452452
{{ t("app.buttons.btnSignPersonalMsg") }}
453453
</Button>
454-
<Button :loading="authenticateUserLoading" block size="xs" pill class="mb-2" @click="onAuthenticateUser">Get id token</Button>
454+
<Button :loading="getIdentityTokenLoading" block size="xs" pill class="mb-2" @click="ongetIdentityToken">Get id token</Button>
455455
</Card>
456456

457457
<!-- SOLANA -->
@@ -473,7 +473,7 @@ const onSwitchChainNamespace = async () => {
473473
<Button block size="xs" pill class="mb-2" @click="onSignAllTransactions">
474474
{{ t("app.buttons.btnSignAllTransactions") }}
475475
</Button>
476-
<Button :loading="authenticateUserLoading" block size="xs" pill class="mb-2" @click="onAuthenticateUser">Get id token</Button>
476+
<Button :loading="getIdentityTokenLoading" block size="xs" pill class="mb-2" @click="ongetIdentityToken">Get id token</Button>
477477
</Card>
478478
</Card>
479479
<Card

demo/wagmi-react-app/src/components/Main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Main = () => {
2828
const { showCheckout, loading: isCheckoutLoading, error: checkoutError } = useCheckout();
2929
const { showWalletConnectScanner, loading: isWalletConnectScannerLoading, error: walletConnectScannerError } = useWalletConnectScanner();
3030
const { showWalletUI, loading: isWalletUILoading, error: walletUIError } = useWalletUI();
31-
const { token, loading: isUserTokenLoading, error: userTokenError, authenticateUser } = useIdentityToken();
31+
const { token, loading: isUserTokenLoading, error: userTokenError, getIdentityToken } = useIdentityToken();
3232
const { switchChainAsync, chains } = useSwitchChain();
3333
const chainId = useChainId();
3434

@@ -57,7 +57,7 @@ const Main = () => {
5757
{isUserTokenLoading ? (
5858
<p>Authenticating...</p>
5959
) : (
60-
<button onClick={() => authenticateUser()} className={styles.card}>
60+
<button onClick={() => getIdentityToken()} className={styles.card}>
6161
Authenticate User
6262
</button>
6363
)}

demo/wagmi-react-app/src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const web3authConfig: Web3AuthContextConfig = {
1717
web3AuthNetwork: "sapphire_devnet",
1818
clientId: clientId,
1919
authBuildEnv: "testing",
20+
uiConfig: {
21+
uxMode: "redirect",
22+
},
2023
},
2124
};
2225

packages/modal/src/react/hooks/useIdentityToken.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface IUseIdentityToken {
77
loading: boolean;
88
error: Web3AuthError | null;
99
token: string | null;
10-
authenticateUser: () => Promise<string | null>;
10+
getIdentityToken: () => Promise<string | null>;
1111
}
1212

1313
export const useIdentityToken = () => {
@@ -17,11 +17,11 @@ export const useIdentityToken = () => {
1717
const [error, setError] = useState<Web3AuthError | null>(null);
1818
const [token, setToken] = useState<string | null>(null);
1919

20-
const authenticateUser = useCallback(async () => {
20+
const getIdentityToken = useCallback(async () => {
2121
setLoading(true);
2222
setError(null);
2323
try {
24-
const userAuthInfo = await web3Auth.authenticateUser();
24+
const userAuthInfo = await web3Auth.getIdentityToken();
2525
if (userAuthInfo?.idToken) {
2626
setToken(userAuthInfo.idToken);
2727
}
@@ -39,5 +39,5 @@ export const useIdentityToken = () => {
3939
}
4040
}, [isConnected, token]);
4141

42-
return { loading, error, token, authenticateUser };
42+
return { loading, error, token, getIdentityToken };
4343
};

packages/modal/src/ui/loginModal.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { applyWhiteLabelTheme, LANGUAGES, SafeEventEmitter } from "@web3auth/aut
66
import {
77
type BaseConnectorConfig,
88
type ChainNamespaceType,
9-
type CONNECTED_EVENT_DATA,
109
CONNECTOR_EVENTS,
1110
type IConnectorDataEvent,
1211
log,
1312
LOGIN_MODE,
1413
type LoginMethodConfig,
14+
LoginModeType,
1515
type MetaMaskConnectorData,
16+
type SDK_CONNECTED_EVENT_DATA,
1617
type WALLET_CONNECTOR_TYPE,
1718
WALLET_CONNECTORS,
1819
type WalletConnectV2Data,
@@ -365,7 +366,7 @@ export class LoginModal {
365366

366367
this.setState({ status: MODAL_STATUS.CONNECTING });
367368
});
368-
listener.on(CONNECTOR_EVENTS.CONNECTED, (data: CONNECTED_EVENT_DATA) => {
369+
listener.on(CONNECTOR_EVENTS.CONNECTED, (data: SDK_CONNECTED_EVENT_DATA) => {
369370
log.debug("connected with connector", data);
370371
// only show success if not being reconnected again.
371372
if (!data.reconnected && data.loginMode === LOGIN_MODE.MODAL) {
@@ -381,8 +382,9 @@ export class LoginModal {
381382
}
382383
});
383384
// TODO: send connector name in error
384-
listener.on(CONNECTOR_EVENTS.ERRORED, (error: Web3AuthError) => {
385+
listener.on(CONNECTOR_EVENTS.ERRORED, (error: Web3AuthError, loginMode: LoginModeType) => {
385386
log.error("error", error, error.message);
387+
if (loginMode === LOGIN_MODE.NO_MODAL) return;
386388
if (error.code === 5000) {
387389
if (this.uiConfig.displayErrorsOnModal)
388390
this.setState({

packages/modal/src/vue/composables/useIdentityToken.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface IUseIdentityToken {
77
loading: Ref<boolean>;
88
error: Ref<Web3AuthError | null>;
99
token: Ref<string | null>;
10-
authenticateUser: () => Promise<string | null>;
10+
getIdentityToken: () => Promise<string | null>;
1111
}
1212

1313
export const useIdentityToken = (): IUseIdentityToken => {
@@ -16,12 +16,12 @@ export const useIdentityToken = (): IUseIdentityToken => {
1616
const error = ref<Web3AuthError | null>(null);
1717
const token = ref<string | null>(null);
1818

19-
const authenticateUser = async () => {
19+
const getIdentityToken = async () => {
2020
try {
2121
if (!web3Auth.value) throw WalletInitializationError.notReady();
2222
error.value = null;
2323
loading.value = true;
24-
const result = await web3Auth.value.authenticateUser();
24+
const result = await web3Auth.value.getIdentityToken();
2525
if (result?.idToken) {
2626
token.value = result.idToken;
2727
}
@@ -43,6 +43,6 @@ export const useIdentityToken = (): IUseIdentityToken => {
4343
loading,
4444
error,
4545
token,
46-
authenticateUser,
46+
getIdentityToken,
4747
};
4848
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type {
1212
ConnectorEvents,
1313
ConnectorInitOptions,
1414
IConnector,
15+
IdentityTokenInfo,
1516
IProvider,
16-
UserAuthInfo,
1717
UserInfo,
1818
} from "./interfaces";
1919

@@ -101,6 +101,6 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
101101
abstract getUserInfo(): Promise<Partial<UserInfo>>;
102102
abstract enableMFA(params?: T): Promise<void>;
103103
abstract manageMFA(params?: T): Promise<void>;
104-
abstract authenticateUser(): Promise<UserAuthInfo>;
104+
abstract getIdentityToken(): Promise<IdentityTokenInfo>;
105105
abstract switchChain(params: { chainId: string }): Promise<void>;
106106
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import type { ChainNamespaceType, ConnectorNamespaceType, CustomChainConfig } from "../chain/IChainInterface";
1818
import type { IWeb3AuthCoreOptions } from "../core/IWeb3Auth";
1919
import { Web3AuthError } from "../errors";
20-
import type { LoginModeType, ProjectConfig } from "../interfaces";
20+
import type { ProjectConfig } from "../interfaces";
2121
import type { ProviderEvents, SafeEventEmitterProvider } from "../provider/IProvider";
2222
import { WALLET_CONNECTOR_TYPE } from "../wallet";
2323
import { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_STATUS } from "./constants";
@@ -41,7 +41,7 @@ export interface ConnectorInitOptions {
4141

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

44-
export type UserAuthInfo = { idToken: string };
44+
export type IdentityTokenInfo = { idToken: string };
4545

4646
export interface BaseConnectorSettings {
4747
coreOptions: IWeb3AuthCoreOptions;
@@ -81,7 +81,7 @@ export interface IConnector<T> extends SafeEventEmitter {
8181
enableMFA(params?: T): Promise<void>;
8282
manageMFA(params?: T): Promise<void>;
8383
switchChain(params: { chainId: string }): Promise<void>;
84-
authenticateUser(): Promise<UserAuthInfo>;
84+
getIdentityToken(): Promise<IdentityTokenInfo>;
8585
cleanup?(): Promise<void>;
8686
}
8787

@@ -100,8 +100,6 @@ export type CONNECTED_EVENT_DATA = {
100100
connector: WALLET_CONNECTOR_TYPE;
101101
provider: IProvider;
102102
reconnected: boolean;
103-
// only available from no-modal instance.
104-
loginMode?: LoginModeType;
105103
};
106104

107105
export interface IConnectorDataEvent {

0 commit comments

Comments
 (0)