Skip to content

Commit

Permalink
Change callback format for Authorize response for iOS 11+
Browse files Browse the repository at this point in the history
  • Loading branch information
cocojoe committed Dec 11, 2018
1 parent 512873b commit af6fea7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions ios/A0Auth0.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ - (dispatch_queue_t)methodQueue
}

RCT_EXPORT_METHOD(showUrl:(NSString *)urlString closeOnLoad:(BOOL)closeOnLoad callback:(RCTResponseSenderBlock)callback) {
if (@available(iOS 11.0, *)) {
self.sessionCallback = callback;
self.closeOnLoad = closeOnLoad;
if (@available(iOS 13.0, *)) {
[self presentAuthenticationSession:[NSURL URLWithString:urlString]];
} else {
[self presentSafariWithURL:[NSURL URLWithString:urlString]];
}
self.sessionCallback = callback;
self.closeOnLoad = closeOnLoad;
}

RCT_EXPORT_METHOD(oauthParameters:(RCTResponseSenderBlock)callback) {
Expand Down Expand Up @@ -89,12 +89,12 @@ - (void)presentAuthenticationSession:(NSURL *)url {
if ([[error domain] isEqualToString:ASWebAuthenticationSessionErrorDomain]) {
switch ([error code]) {
case SFAuthenticationErrorCanceledLogin:
callback(@[ERROR_CANCELLED]);
callback(@[ERROR_CANCELLED, [NSNull null]]);
}
} else if(error) {
callback(@[error]);
callback(@[error, [NSNull null]]);
} else if(callbackURL) {
callback(@[@{@"url": callbackURL.absoluteString}]);
callback(@[[NSNull null], callbackURL.absoluteString]);
}
self.authenticationSession = nil;
}];
Expand All @@ -107,12 +107,12 @@ - (void)presentAuthenticationSession:(NSURL *)url {
if ([[error domain] isEqualToString:SFAuthenticationErrorDomain]) {
switch ([error code]) {
case SFAuthenticationErrorCanceledLogin:
callback(@[ERROR_CANCELLED]);
callback(@[ERROR_CANCELLED, [NSNull null]]);
}
} else if(error) {
callback(@[error]);
callback(@[error, [NSNull null]]);
} else if(callbackURL) {
callback(@[@{@"url": callbackURL.absoluteString}]);
callback(@[[NSNull null], callbackURL.absoluteString]);
}
self.authenticationSession = nil;
}];
Expand All @@ -127,11 +127,11 @@ - (void)terminateWithError:(id)error dismissing:(BOOL)dismissing animated:(BOOL)
[self.last.presentingViewController dismissViewControllerAnimated:animated
completion:^{
if (error) {
callback(@[error]);
callback(@[error, [NSNull null]]);
}
}];
} else if (error) {
callback(@[error]);
callback(@[error, [NSNull null]]);
}
self.sessionCallback = nil;
self.last = nil;
Expand Down
12 changes: 6 additions & 6 deletions webauth/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default class Agent {
resolve(event.url);
};
Linking.addEventListener('url', urlHandler);
NativeModules.A0Auth0.showUrl(url, closeOnLoad, result => {
NativeModules.A0Auth0.showUrl(url, closeOnLoad, (error, redirectURL) => {
Linking.removeEventListener('url', urlHandler);
if (result && result.url) {
resolve(result.url);
} else if (result) {
reject(result);
} else if (closeOnLoad) {
if (error) {
reject(error);
} else if(redirectURL) {
resolve(redirectURL);
} else if(closeOnLoad) {
resolve();
}
});
Expand Down

0 comments on commit af6fea7

Please sign in to comment.