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:
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
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.
Link wallet to existing account
If you already have an authenticated user and want to link an additional external wallet to their account, use initLinkSiwe and linkWithSiwe.
Initialize link challenge
import openfort from "./openfortConfig"
async function initLinkSiwe(address: string) {
const challenge = await openfort.auth.initLinkSiwe({ address });
return challenge.nonce;
}Link with signature
import openfort from "./openfortConfig"
async function linkWallet(
signature: string,
message: string,
address: string,
chainId: number,
walletClientType: string,
connectorType: string
) {
await openfort.auth.linkWithSiwe({
signature: signature,
message: message,
address: address,
chainId: chainId,
walletClientType: walletClientType,
connectorType: connectorType,
});
console.log('Wallet linked successfully');
}For more details on linking and unlinking accounts, see Linking & unlinking accounts.