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.
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
| Step | Electron FFI | WASM |
|---|---|---|
| Configure server addresses and runtime | initSDK(InitConfig) | Included in login(InitAndLoginConfig) |
| Submit user credentials | login({ userID, token }) | Included in the same login() call |
| Release the native SDK | unInitSDK() | 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
| Field | Type | Required | Description |
|---|---|---|---|
apiAddr | string | Yes | OpenIMServer HTTP API address. |
wsAddr | string | Yes | OpenIMServer WebSocket address. |
platformID | number | Yes | Current client platform value. It must conform to the OpenIMServer multi-device login policy. |
dataDir | string | Yes | Writable absolute path for the native SDK's local data. |
systemType | string | Yes | System-type identifier required by the Electron FFI SDK. |
logLevel | LogLevel | No | Logging level. |
logFilePath | string | No | Log-file path. |
isLogStandardOutput | boolean | No | Whether 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
| Field | Type | Required | Description |
|---|---|---|---|
userID | string | Yes | Current OpenIMSDK user ID. Must strictly match the token subject. |
token | string | Yes | OpenIMSDK 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
Was this page helpful?