asgardeo / asgardeo/javascript

[Feature] Implement Multiton Pattern for Enhanced Instance Management in AsgardeoAuthClient

Offen
#368 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Type/Improvement
Vorherrschende Sprache
TypeScript
Sterne
18
Forks
67
Ø Merge
4 Std. 6 Min.
Gemergte PRs (30 T.)
13

Beschreibung

### Current Limitation

The `AsgardeoAuthClient ` currently relies on a public constructor, allowing for the uncontrolled creation of multiple instances without a centralized management system. Unlike the browser-specific implementations in the SDK ecosystem, there is no static mechanism to track, retrieve, or properly dispose of active client instances.

This lack of lifecycle management creates several issues:

- Inconsistency: It diverges from the architectural patterns used elsewhere in the SDK, leading to a fragmented developer experience.
- Resource Management: There is no standard way to destroy an instance or clear its session data, which poses risks for memory leaks.
- Multi-tenancy issues: Applications needing multiple isolated authentication contexts (e.g., distinct organization sessions) have no reliable way to manage and access specific instances by ID.
- Testing challenges: Without a way to destroyAllInstances(), ensuring a clean state between unit tests is difficult.

### Suggested Improvement

Refactor the AsgardeoAuthClient to implement the Multiton Pattern. This involves restricting direct instantiation and managing instances via a static internal map.

Specific changes recommended:

- Protected Constructor: Change the constructor visibility to protected to prevent direct usage of new AsgardeoAuthClient().
- Static Instance Map: Introduce a static Map to store active instances.
- Factory Method: Implement a static getInstance(id?: number) method that creates a new instance only if one does not exist for the given ID.
- Lifecycle Methods: Add utility methods to support proper cleanup:
- destroyInstance(id)
- destroyAllInstances()
- hasInstance(id)

### Please select the package issue is related to

@asgardeo/javascript

### Version

N/A

### Reporter Checklist

- [x] I have searched the existing issues and this is not a duplicate.
- [x] I have provided all the necessary information.
- [x] I have verified the improvement is not available in the latest version of the package.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, AsgardeoAuthClient im @asgardeo/javascript-Paket zu finden und die im Issue referenzierten browserspezifischen SDK-Implementierungen zu prüfen. Bestätige das erforderliche Design für geschützte Konstruktion, ID-basierte Instanzabfrage und die Bereinigung des Lebenszyklus; als erledigt gilt dies, wenn getInstance, destroyInstance, destroyAllInstances und hasInstance isolierte Clients sowie einen sauberen Testzustand unterstützen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
authentication
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.