Session & Network
Read the active session, switch networks, and refresh the JWT. Works identically across Bitcoin + EVM.
Every SDK method that touches a wallet reads from the session — a small in-memory object that holds the user's address, network, hdkeys, and auth token. This page covers reading, updating, and clearing it.
Read the session
import { getSession } from '@oviato/connect';
const session = getSession();
if (!session) {
// User isn't logged in
} else {
console.log(session.username); // 'alice'
console.log(session.address); // 'bc1q...' or '0x...'
console.log(session.network); // 'bitcoin' | 'eth' | 'base' | ...
console.log(session.networkType); // 'utxo' | 'evm'
}React hook equivalent
import { useOviConnect } from '@oviato/connect/client';
function Profile() {
const { session, isLoading, disconnect } = useOviConnect();
if (isLoading) return <p>Loading…</p>;
if (!session) return <p>Please connect</p>;
return (
<div>
<p>{session.username}</p>
<button onClick={disconnect}>Disconnect</button>
</div>
);
}Check whether authenticated
import { isAuthenticated } from '@oviato/connect';
if (isAuthenticated()) {
// Session exists AND JWT hasn't expired
}This is stricter than !!getSession() — it also checks that the bearer token is still valid (not expired).
Clear the session
import { clearSession } from '@oviato/connect';
clearSession();Wipes the in-memory store + the localStorage cache. The user's passkey isn't affected — they can login() again and pick up where they left off.
Server-side sessions aren't revoked — only the client-side copy is dropped.
If you need to revoke the JWT server-side (account takeover, compromised
device), call auth.revokeToken() via the dashboard.
Switch network
Changes the active chain. Requires a passkey tap because the SDK re-signs the session JWT for the new chain — this prevents a stolen JWT from being silently repointed.
import { switchNetwork, Network } from '@oviato/connect';
const r = await switchNetwork(Network.BASEMAINNET);
if (r.status === 'success' && r.type === 'switchNetworkSuccess') {
console.log('Now on', r.data.network);
console.log('New address:', r.data.session.address);
}What changes
Switching networks re-derives the user's address (addresses are deterministic per (user, app, network)) and re-issues the JWT with a chain-scoped claim. After a successful switch:
session.network→ the new networksession.networkType→'utxo'or'evm'based on the new chainsession.address→ the deterministic address on the new chain- The JWT's
networkclaim matches — required for write methods
Supported networks
Network.BTCMAINNET('bitcoin')Network.BTCTESTNET('bitcointestnet')Network.ETHMAINNET('eth')Network.ETHSEPOLIA('ethsepolia')Network.BASEMAINNET('base')Network.BASESEPOLIA('basesepolia')
More come online via the dashboard. If you try to switch to an unsupported network for your app, the call fails with a clear error.
Ethers-style alias
import { evm } from '@oviato/connect';
await evm.switchChain(Network.BASEMAINNET);Identical to switchNetwork — kept for ethers-ecosystem familiarity.
The session shape
type Session = {
username: string;
address: string;
publicKey: string;
network: Network;
networkType: 'utxo' | 'evm';
hdKeys?: { mainnet: string; testnet: string; solana: string };
pk?: string;
auth?: {
token: string; // Bearer JWT
expires: string; // ISO 8601
};
};Subscribe to session changes (React)
import { useOviConnect } from '@oviato/connect/client';
function App() {
const { session } = useOviConnect();
useEffect(() => {
if (session) {
console.log('User logged in:', session.address);
} else {
console.log('User logged out');
}
}, [session]);
}For vanilla JS, the underlying store is Zustand — subscribe directly:
import { oviStore } from '@oviato/connect';
const unsub = oviStore.subscribe((state) => {
console.log('Session changed:', state.session);
});Related
- Authentication — login/register/authenticate flows
- Core Concepts → Sessions are chain-scoped