Login & Logout
login()
Section titled “login()”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 emailIf 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 configuredloginTimeout(default: 5 minutes)WidgetError— if the widget reports an authentication error (wrong password, network issue, etc.)
Opening the widget conditionally
Section titled “Opening the widget conditionally”if (!client.isLoggedIn) { await client.login();}// Now safe to proceedlogout()
Section titled “logout()”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.
destroy()
Section titled “destroy()”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 stilllogin()againdestroy()removes everything — you’d need to create a newOxGasAuthinstance after this
React example
Section titled “React example”useEffect(() => { return () => { // Clean up when the component unmounts auth.destroy(); };}, []);isConnected()
Section titled “isConnected()”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.