[Feature] Implement Multiton Pattern for Enhanced Instance Management in AsgardeoAuthClient
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- authentication
Research direction
Start by locating AsgardeoAuthClient in the @asgardeo/javascript package and reviewing the browser-specific SDK implementations referenced in the issue. Confirm the design needed for protected construction, ID-keyed instance retrieval, and lifecycle cleanup; done means getInstance, destroyInstance, destroyAllInstances, and hasInstance support isolated clients and clean test state.
Written by the indexing model from the issue text.
Description
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<number, AsgardeoAuthClient> 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
- I have searched the existing issues and this is not a duplicate.
- I have provided all the necessary information.
- I have verified the improvement is not available in the latest version of the package.
- Dominant language
- TypeScript
- Stars
- 18
- Forks
- 67
- Avg merge
- 4h 6m
- Merged PRs (30d)
- 13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from asgardeo/javascript
-
Bug: SignInButton render prop usage in "react-tanstack-router" sample missing "onClick={signIn}" OpenType/Bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
asgardeo/javascript#572 ·
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
asgardeo/javascript#571 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
asgardeo/javascript#485 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
asgardeo/javascript#527 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
asgardeo/javascript#522 · 2 comments ·
All issues in asgardeo/javascript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·