Skip to content

Commit 0ef9351

Browse files
authored
feat: Add PFUser.unregisterAuthenticationDelegate and allow to register delegate gracefully if another delegate is already registered (#1711)
1 parent b885a65 commit 0ef9351

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Parse/Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ - (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
5555
forAuthType:(NSString *)authType {
5656
PFParameterAssert(delegate, @"Authentication delegate can't be `nil`.");
5757
PFParameterAssert(authType, @"`authType` can't be `nil`.");
58-
PFParameterAssert(![self authenticationDelegateForAuthType:authType],
59-
@"Authentication delegate already registered for authType `%@`.", authType);
58+
59+
// If auth delete is already registered then unregister it gracefully
60+
if ([self authenticationDelegateForAuthType:authType]) {
61+
NSLog(@"unregistering existing deletegate to gracefully register new delegate for authType `%@`.", authType);
62+
[self unregisterAuthenticationDelegateForAuthType:authType];
63+
}
64+
6065
dispatch_sync(_dataAccessQueue, ^{
6166
self->_authenticationDelegates[authType] = delegate;
6267
});

Parse/Parse/Source/PFUser.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ typedef void(^PFUserLogoutResultBlock)(NSError *_Nullable error);
283283
///--------------------------------------
284284

285285
/**
286-
Registers a third party authentication delegate.
286+
Registers a third party authentication delegate. If a delegate is already registered for the authType then
287+
it is replaced by the new delegate.
287288
288289
@note This method shouldn't be invoked directly unless developing a third party authentication library.
289290
@see PFUserAuthenticationDelegate
@@ -293,6 +294,16 @@ typedef void(^PFUserLogoutResultBlock)(NSError *_Nullable error);
293294
*/
294295
+ (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegate forAuthType:(NSString *)authType;
295296

297+
/**
298+
Unregisters a third party authentication delegate. If no delegate is registered, this fails gracefully.
299+
300+
@note This method shouldn't be invoked directly unless developing a third party authentication library.
301+
@see PFUserAuthenticationDelegate
302+
303+
@param authType The name of the type of third party authentication source.
304+
*/
305+
+ (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType;
306+
296307
/**
297308
Logs in a user with third party authentication credentials.
298309

Parse/Parse/Source/PFUser.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ + (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
848848
[[self authenticationController] registerAuthenticationDelegate:delegate forAuthType:authType];
849849
}
850850

851+
+ (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
852+
[[self authenticationController] unregisterAuthenticationDelegateForAuthType:authType];
853+
}
854+
851855
#pragma mark Log In
852856

853857
+ (BFTask<__kindof PFUser *> *)logInWithAuthTypeInBackground:(NSString *)authType

0 commit comments

Comments
 (0)