Skip to content

Login & Logout

Opens the authentication widget and returns a WalletInfo object once the user logs in.

const wallet = await auth.login();
// wallet.address — the EOA address backed by KMS
// wallet.email — the user's registered email

If the user is already logged in, login() returns immediately without opening the widget. It never throws if the user is authenticated.

Throws:

  • SigningTimeoutError — if the user doesn’t complete login within the configured loginTimeout (default: 5 minutes)
  • WidgetError — if the widget reports an authentication error (wrong password, network issue, etc.)
if (!client.isLoggedIn) {
await client.login();
}
// Now safe to proceed

Ends the user’s session, clears stored wallet info, and removes the iframe from the page.

await auth.logout();

This sends a LOGOUT message to the widget before tearing it down. The widget clears the access token in response. After this call, isConnected() returns false and getWalletInfo() returns null.

Note: logout() is asynchronous because it posts a message to the iframe, but it resolves quickly — you don’t need to wait for KMS cleanup.


Full teardown. Clears state, removes the iframe, and removes all event listeners.

auth.destroy();

Call this when the component or page using OxGasAuth is unmounting. It prevents memory leaks and stale event listeners.

The difference from logout():

  • logout() clears the session but keeps listeners, so your app can still login() again
  • destroy() removes everything — you’d need to create a new OxGasAuth instance after this
useEffect(() => {
return () => {
// Clean up when the component unmounts
auth.destroy();
};
}, []);

Returns true if the user is currently logged in and wallet info is available.

if (auth.isConnected()) {
const address = auth.getAddress();
console.log('Wallet:', address);
}

This checks both the internal state ("connected") and whether wallet info exists. It returns false during the brief "connecting" transition while login is in progress.