External Wallet Login
Connect wallet via the Sign in With Ethereum (SIWE) standard. Catered to users who prefer to authenticate using their external wallets, supporting various types such as injected, browser-based, and mobile wallets. Openfort's integration facilitates a secure and direct authentication process using these wallets.
Initialize SIWE challenge
Create a challenge for the user to sign with their wallet. The initSiwe method returns a SIWEInitResponse with the nonce:
auth.tsx
import openfort from "./openfortConfig"
async function initSiwe(address: string) {
const challenge = await openfort.auth.initSiwe({ address });
console.log('Nonce:', challenge.nonce);
return challenge;
}Login with SIWE
Verify the SIWE signature to authenticate the user. The loginWithSiwe method returns an AuthResponse:
walletClientType: for example,coinbaseWallet,metamaskconnectorType: for example,wallet_connect_v2,injected,coinbase_wallet
authSIWE.tsx
import openfort from "./openfortConfig"
async function loginWithSiwe(
signature: string,
message: string,
address: string,
walletClientType: string,
connectorType: string
) {
const result = await openfort.auth.loginWithSiwe({
signature: signature,
message: message,
address: address,
walletClientType: walletClientType,
connectorType: connectorType,
});
console.log('User logged in:', result.user.id);
console.log('Access token:', result.token);
}Upon successful authentication, the SDK returns an AuthResponse containing the user's session token and profile information.