Skip to content

clear() does not disconnect the active WASM connection, but nothing in the API signals that disconnect() must also be called #189

Description

@wankhede04

LightningNodeConnect.clear(options?: ClearOptions) only clears credential state — it
calls _authCoordinator.clearSession() and, if options.persisted === true,
_strategyManager.clearAll(). It never calls into _wasmManager in any branch, so the
live WASM connection (and the underlying wasmClientIsConnected/wasmClientInvokeRPC
state) stays fully alive after clear() returns.

Tearing down the connection requires the separate disconnect() method
(WasmManager.disconnect() removes the unload listener and calls
wasmClientDisconnect()), and the README's "Clearing Credentials" section already
acknowledges the gap in practice by recommending a full window.location.reload() after
clear() to guarantee a clean state, rather than documenting clear() + disconnect()
as the two calls a full logout requires.

The problem is discoverability, not just documentation. An integrator building a logout
flow has no signal from the method name, the ClearOptions type, or TypeScript itself
that clear() is credential-only — "clear" reads as the complete logout action. Skipping
disconnect() leaves the app in a state where credentials are gone but the WASM client is
still connected and could still be invoked via any RPC method that doesn't check auth
state client-side, until eventually cleaned up by an unload event the app may not even
trigger (e.g. an SPA route change with no full page reload).

Proposing one of:

  1. Have clear() also call the equivalent of disconnect() by default (with an opt-out
    for callers who genuinely want credentials cleared but the socket kept alive), or
  2. Add an explicit disconnect: boolean field to ClearOptions so a full logout is one
    call (clear({ persisted: true, disconnect: true })) instead of two separately-named,
    easy-to-forget methods.

Happy to send a PR for either direction once the preferred approach is confirmed — opening
this first since it changes default behavior of a widely-used public method, which felt
worth discussing before code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions