worldcoin / idkit-js

Javascript toolkit to interact with the World ID protocol. Building the Identity SDK.
https://docs.worldcoin.org
MIT License
280 stars 71 forks source link

Adding `IDKit.isInitialized` Flag to Check Initialization Status #256

Closed erados closed 1 month ago

erados commented 3 months ago

Description:

Currently, the IDKit can only be initialized once. To ensure that the initialization process is managed correctly, it would be beneficial to have a flag indicating whether the IDKit has been initialized. This flag, IDKit.isInitialized, would help developers avoid reinitialization attempts and manage the initialization state more effectively.

Proposed Solution:

Introduce a boolean flag IDKit.isInitialized that:

Benefits:

  1. Prevent Reinitialization: By checking the isInitialized flag, developers can avoid unnecessary or erroneous reinitialization attempts.
  2. State Management: Provides a clear and straightforward way to manage the initialization state within the application.
  3. Error Handling: Helps in implementing more robust error handling by checking the initialization state before performing operations that depend on IDKit.

Example Usage:

if (!IDKit.isInitialized) {
    IDKit.initialize();
}

// Safe to proceed with operations that require IDKit to be initialized
if (IDKit.isInitialized) {
    // Perform operations
}

Thank you for considering this enhancement. It would greatly improve the usability and reliability of the IDKit in various scenarios.

image

Ivanciro27 commented 3 months ago

if (!IDKit.isInitialized) { IDKit.initialize(); }

// Safe to proceed with operations that require IDKit to be initialized if (IDKit.isInitialized) { // Perform operations }