Handle Auto-Connect and Session Management
mainThe SDK can automatically reconnect to existing sessions to provide a seamless experience. This is controlled by the autoConnect option.
autoConnect: true(Default for embedded): The SDK checks for a valid session immediately upon instantiation. If a session exists, it connects in the background.autoConnect: false: You must manually callsdk.connect()every time the user needs to authenticate.
Pattern for checking connection:
Always check sdk.isConnected() (or sdk.solana.isConnected / sdk.ethereum.isConnected()) before attempting to use the SDK to determine if a manual connect() call is required.
const sdk = new BrowserSDK({
providers: ["google", "apple"],
appId: "your-app-id",
addressTypes: [AddressType.solana],
autoConnect: true,
});
if (sdk.isConnected()) {
// Use existing session
const addresses = await sdk.getAddresses();
} else {
// Trigger manual connection
await sdk.connect({ provider: "google" });
}