Browse SDKs · Electron
Platform
SDKsElectron

Authenticate and initialize

Use the Electron FFI initSDK, login, and unInitSDK methods to establish a session, and understand how their parameters differ from WASM login.

Copy

The Electron FFI SDK separates SDK initialization from user authentication. First call initSDK() to configure the OpenIMServer addresses and local runtime directory, then call login() with the userID and token. This differs from WASM authentication and session management, where a single InitAndLoginConfig is passed to login().

This page covers only the Electron FFI lifecycle APIs. Use the WASM authentication page as a reference for the handling boundaries around connection success, token expiration, and forced sign-out. Electron FFI uses its own exported event enum.

Differences from WASM

StepElectron FFIWASM
Configure server addresses and runtimeinitSDK(InitConfig)Included in login(InitAndLoginConfig)
Submit user credentialslogin({ userID, token })Included in the same login() call
Release the native SDKunInitSDK()No equivalent public unload API; use logout() to end the session

If the Electron renderer uses the WASM package, follow the WASM authentication page directly and do not call the initSDK() described here.

Initialize the SDK

At initialization, InitConfig supplies server addresses, platform information, a local data directory, and logging options.

Parameters

FieldTypeRequiredDescription
apiAddrstringYesOpenIMServer HTTP API address.
wsAddrstringYesOpenIMServer WebSocket address.
platformIDnumberYesCurrent client platform value. It must conform to the OpenIMServer multi-device login policy.
dataDirstringYesWritable absolute path for the native SDK's local data.
systemTypestringYesSystem-type identifier required by the Electron FFI SDK.
logLevelLogLevelNoLogging level.
logFilePathstringNoLog-file path.
isLogStandardOutputbooleanNoWhether to write logs to standard output.
await openimsdk.initSDK({
  apiAddr,
  wsAddr,
  platformID,
  dataDir: '/absolute/path/to/openim-data',
  systemType: 'electron',
  logLevel: LogLevel.Warn,
  isLogStandardOutput: false,
});

A successful initSDK() Promise indicates that the native runtime is configured and ready for authentication; at this stage, the WebSocket connection and user session are not yet established.

Log in the current user

Call login() after initSDK() succeeds. FFI login accepts only the user's credentials:

Parameters

FieldTypeRequiredDescription
userIDstringYesCurrent OpenIMSDK user ID. Must strictly match the token subject.
tokenstringYesOpenIMSDK authentication token returned by your application backend.
await openimsdk.login({
  userID,
  token,
});

A successful login() Promise confirms that the credentials were submitted and validated. The persistent WebSocket connection is fully established upon receiving the OnConnectSuccess event, after which normal chat and conversation operations can proceed. See Authenticate and manage a session for complete event listener registration.

Log out and uninitialize

When the user signs out or switches accounts, first call the shared logout() method to end the session. Call unInitSDK() afterward when the native resources must be released.

await openimsdk.logout();
await openimsdk.unInitSDK();

unInitSDK() takes no business parameters. When switching accounts, finish signing out the old account and clear its state before calling initSDK() and login() again when necessary. Do not initialize two native instances concurrently.

Next steps