A single WebSocket connection can host multiple independent sessions, each with its own authentication, namespace, database, and parameters. This is useful for multi-tenant applications where requests act on behalf of different users over one shared connection. The SurrealClient is itself the root session.
Note
API references
| Method | Description |
|---|---|
client.newSession() | Creates a new isolated session |
client.closeSession(session) | Closes a session |
Creating sessions
Each session created with .newSession() is a SurrealSession that exposes the same querying and authentication API as the client, but with isolated state.
Closing sessions
Close a session with .closeSession() when you no longer need it. This does not close the underlying connection.
Learn more
Session reference for the session API
Authentication for per-session credentials
Transactions — transactions run within a session