-
Notifications
You must be signed in to change notification settings - Fork 42
[SDK-149] add-logout-functionality #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
03d7967
954df65
900ee9c
f72f578
b9401df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -890,6 +890,34 @@ export class Iterable { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Logs out the current user from the Iterable SDK. | ||
| * | ||
| * This method will remove all event listeners for the Iterable SDK and set the email and user ID to null. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * Iterable.logout(); | ||
| * ``` | ||
| */ | ||
| static logout() { | ||
| Iterable.removeAllEventListeners(); | ||
| Iterable.setEmail(null); | ||
| Iterable.setUserId(null); | ||
| } | ||
|
|
||
| /** | ||
| * Removes all event listeners for the Iterable SDK. | ||
| */ | ||
| private static removeAllEventListeners() { | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleCustomActionCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthSuccessCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthFailureCalled); | ||
| } | ||
|
Comment on lines
+903
to
+919
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good |
||
|
|
||
| /** | ||
| * Sets up event handlers for various Iterable events. | ||
| * | ||
|
|
@@ -912,12 +940,7 @@ export class Iterable { | |
| */ | ||
| private static setupEventHandlers() { | ||
| // Remove all listeners to avoid duplicate listeners | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled); | ||
| RNEventEmitter.removeAllListeners( | ||
| IterableEventName.handleCustomActionCalled | ||
| ); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled); | ||
| Iterable.removeAllEventListeners(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catching all in one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
|
||
| if (Iterable.savedConfig.urlHandler) { | ||
| RNEventEmitter.addListener(IterableEventName.handleUrlCalled, (dict) => { | ||
|
|
@@ -966,7 +989,7 @@ export class Iterable { | |
| // Asks frontend of the client/app to pass authToken | ||
| Iterable.savedConfig.authHandler!() | ||
| .then((promiseResult) => { | ||
| // Promise result can be either just String OR of type AuthResponse. | ||
| // Promise result can be either just String OR of type AuthRespronse. | ||
|
||
| // If type AuthReponse, authToken will be parsed looking for `authToken` within promised object. Two additional listeners will be registered for success and failure callbacks sent by native bridge layer. | ||
| // Else it will be looked for as a String. | ||
| if (isIterableAuthResponse(promiseResult)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email and userId usually dont go together.
When email is set and we call setUserId, it goes through logging out user with email id and then tries to log in.
So it should ideally be setEmail > logout > assernull for email
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know.. this doesn't call the internal functionality for setting user id
and email, so I'm just doing this as a test to make sure that both are cleared
later. I'll add a comment to address this.