-
Notifications
You must be signed in to change notification settings - Fork 41
[SDK-151] cannot-read-property-authtoken-of-undefined #779
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 all commits
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 |
|---|---|---|
|
|
@@ -23,6 +23,23 @@ import { IterableLogger } from './IterableLogger'; | |
|
|
||
| const RNEventEmitter = new NativeEventEmitter(RNIterableAPI); | ||
|
|
||
| /** | ||
| * Checks if the response is an IterableAuthResponse | ||
| */ | ||
| const isIterableAuthResponse = ( | ||
| response: IterableAuthResponse | string | undefined | null | ||
| ): response is IterableAuthResponse => { | ||
| if (typeof response === 'string') return false; | ||
| if ( | ||
| response?.authToken || | ||
| response?.successCallback || | ||
| response?.failureCallback | ||
| ) { | ||
| return true; | ||
| } | ||
| return false; | ||
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
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. |
||
| }; | ||
|
|
||
| /* eslint-disable tsdoc/syntax */ | ||
| /** | ||
| * The main class for the Iterable React Native SDK. | ||
|
|
@@ -952,33 +969,31 @@ export class Iterable { | |
| // Promise result can be either just String OR of type AuthResponse. | ||
| // 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 (typeof promiseResult === typeof new IterableAuthResponse()) { | ||
| Iterable.authManager.passAlongAuthToken( | ||
| (promiseResult as IterableAuthResponse).authToken | ||
| ); | ||
| if (isIterableAuthResponse(promiseResult)) { | ||
| Iterable.authManager.passAlongAuthToken(promiseResult.authToken); | ||
|
|
||
| setTimeout(() => { | ||
| if ( | ||
| authResponseCallback === IterableAuthResponseResult.SUCCESS | ||
| ) { | ||
| if ((promiseResult as IterableAuthResponse).successCallback) { | ||
| (promiseResult as IterableAuthResponse).successCallback?.(); | ||
| if (promiseResult.successCallback) { | ||
| promiseResult.successCallback?.(); | ||
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
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. |
||
| } | ||
| } else if ( | ||
| authResponseCallback === IterableAuthResponseResult.FAILURE | ||
| ) { | ||
| // We are currently only reporting JWT related errors. In | ||
| // the future, we should handle other types of errors as well. | ||
| if ((promiseResult as IterableAuthResponse).failureCallback) { | ||
| (promiseResult as IterableAuthResponse).failureCallback?.(); | ||
| if (promiseResult.failureCallback) { | ||
| promiseResult.failureCallback?.(); | ||
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
qltysh[bot] marked this conversation as resolved.
Show resolved
Hide resolved
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. |
||
| } | ||
| } else { | ||
| IterableLogger?.log('No callback received from native layer'); | ||
| } | ||
| }, 1000); | ||
| } else if (typeof promiseResult === 'string') { | ||
| //If promise only returns string | ||
| Iterable.authManager.passAlongAuthToken(promiseResult as string); | ||
| Iterable.authManager.passAlongAuthToken(promiseResult); | ||
| } else { | ||
| IterableLogger?.log( | ||
|
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. Can also consider calling failure callback here with appropriate message.
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. Yeahhh I agree.. just don't want to mix concerns in the PR |
||
| 'Unexpected promise returned. Auth token expects promise of String or AuthResponse type.' | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.