Skip to content

Commit

Permalink
fix(clerk-react): IsomorphicClerk#addListener should return unsubscri…
Browse files Browse the repository at this point in the history
…be method

Issue: #1451
  • Loading branch information
dimkl committed Jul 5, 2023
1 parent 50cea32 commit f6b77a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-llamas-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-react': minor
---

Update IsomorphicClerk#addListener to correctly return an unsubscribe method
9 changes: 6 additions & 3 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import type {
DomainOrProxyUrl,
HandleMagicLinkVerificationParams,
HandleOAuthCallbackParams,
ListenerCallback,
OrganizationMembershipResource,
OrganizationResource,
RedirectOptions,
Resources,
SetActiveParams,
SignInProps,
SignOut,
SignOutCallback,
SignOutOptions,
SignUpProps,
UnsubscribeCallback,
UserButtonProps,
UserProfileProps,
UserResource,
Expand Down Expand Up @@ -542,12 +543,14 @@ export default class IsomorphicClerk {
}
};

addListener = (listener: (emission: Resources) => void): void => {
addListener = (listener: ListenerCallback): UnsubscribeCallback => {
const callback = () => this.clerkjs?.addListener(listener);

if (this.clerkjs) {
callback();
return callback() as UnsubscribeCallback;
} else {
this.premountMethodCalls.set('addListener', callback);
return () => this.premountMethodCalls.delete('addListener');
}
};

Expand Down

0 comments on commit f6b77a1

Please sign in to comment.