Browse SDKs · Electron
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. For complete listener registration and cleanup for connection success, token expiration, and forced sign-out, follow the WASM authentication page. Shared capabilities use the same method names and CbEvents values.

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,
});

When the initSDK() Promise succeeds, the native SDK has initialized and can proceed to login. It has not established a user session, and a connection event has not necessarily arrived.

Log in the current user

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

Parameters

FieldTypeRequiredDescription
userIDstringYesCurrent OpenIMSDK user ID. It must match the token.
tokenstringYesOpenIMSDK token issued by a trusted backend.
await openimsdk.login({
  userID,
  token,
});

When the login() Promise succeeds, the login request has completed. Use connection events such as OnConnectSuccess to decide when business APIs that require a connection are available. See the WASM authentication page for event 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