-
Notifications
You must be signed in to change notification settings - Fork 209
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
Added clearSession iOS Safari Method #65
Conversation
Also ran it through Xcode/Re-Indent 😄 |
Note: Sample PR auth0-samples/auth0-react-native-sample#4 |
webauth/index.js
Outdated
clearSession(options = {}, callback) { | ||
const { clientId, domain, client, agent } = this; | ||
const federated = options.federated || false; | ||
A0Auth0.clearSession(domain, federated, callback); |
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.
Since this method is not yet available on android lets fail when the OS is not iOS.
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.
webauth/index.js
Outdated
* | ||
* @memberof WebAuth | ||
*/ | ||
clearSession(options = {}, callback) { |
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.
The library uses promises instead of callbacks
Added clearSession JS wrapper
Added iOS platform check to method
5fb74c3
to
4c6cb1a
Compare
Ping |
ios/A0Auth0.m
Outdated
self.sessionCallback = callback; | ||
} | ||
|
||
RCT_EXPORT_METHOD(clearSession:(NSString *)domain federated:(BOOL)federated callback:(RCTResponseSenderBlock)callback) { | ||
NSString *urlString = [NSString stringWithFormat:@"https://%@/v2/logout", domain]; |
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.
Lets use NSURLComponents to build urls
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.
And TBH I'd rather build the full url in JS and make this method a more generic one like show and close on load thing
ios/A0Auth0.m
Outdated
[self terminateWithError:error dismissing:NO animated:NO]; | ||
} | ||
|
||
- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully { | ||
if (!didLoadSuccessfully) { | ||
if (self.didLoadCallback) { | ||
didLoadSuccessfully ? self.didLoadCallback(@[[NSNull null]]) : self.didLoadCallback(@[@{@"error": @"failed to load"}]); |
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.
Probably cleaner to do the ternary operator with the parameter and the call the callback later
ios/A0Auth0.m
Outdated
}; | ||
@"error": @"a0.session.failed_load", | ||
@"error_description": @"Failed to load authorize url" | ||
}; | ||
[self terminateWithError:error dismissing:YES animated:YES]; |
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.
We need to clean the didLoadCallback too
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.
What are you thinking here, refactor it all to use the didLoadCallback
and make the auto close optional?
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.
Ignore that, out of scope of this PR.
webauth/index.js
Outdated
return new Promise(function (resolve, reject) { | ||
if (Platform.OS !== 'ios') { reject(new Error('clearSession only supported in iOS')); } | ||
A0Auth0.clearSession(domain, federated, function (err, data) { | ||
if (err !== null) return reject(err); |
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.
Always use {}
Move URL builder to JS Tidy up code
Improve error message and use AuthError type
Make use of Auth client url builder. Make iOS implementation reuse existing handlers
7f0edb0
to
493ed73
Compare
Added clearSession JS wrapper