Skip to content

Commit

Permalink
feat: Add PFUser.unregisterAuthenticationDelegate and allow to regi…
Browse files Browse the repository at this point in the history
…ster delegate gracefully if another delegate is already registered (#1711)
  • Loading branch information
mtrezza authored Feb 22, 2023
1 parent b885a65 commit 0ef9351
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ - (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
forAuthType:(NSString *)authType {
PFParameterAssert(delegate, @"Authentication delegate can't be `nil`.");
PFParameterAssert(authType, @"`authType` can't be `nil`.");
PFParameterAssert(![self authenticationDelegateForAuthType:authType],
@"Authentication delegate already registered for authType `%@`.", authType);

// If auth delete is already registered then unregister it gracefully
if ([self authenticationDelegateForAuthType:authType]) {
NSLog(@"unregistering existing deletegate to gracefully register new delegate for authType `%@`.", authType);
[self unregisterAuthenticationDelegateForAuthType:authType];
}

dispatch_sync(_dataAccessQueue, ^{
self->_authenticationDelegates[authType] = delegate;
});
Expand Down
13 changes: 12 additions & 1 deletion Parse/Parse/Source/PFUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ typedef void(^PFUserLogoutResultBlock)(NSError *_Nullable error);
///--------------------------------------

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

/**
Unregisters a third party authentication delegate. If no delegate is registered, this fails gracefully.
@note This method shouldn't be invoked directly unless developing a third party authentication library.
@see PFUserAuthenticationDelegate
@param authType The name of the type of third party authentication source.
*/
+ (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType;

/**
Logs in a user with third party authentication credentials.
Expand Down
4 changes: 4 additions & 0 deletions Parse/Parse/Source/PFUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,10 @@ + (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
[[self authenticationController] registerAuthenticationDelegate:delegate forAuthType:authType];
}

+ (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
[[self authenticationController] unregisterAuthenticationDelegateForAuthType:authType];
}

#pragma mark Log In

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

0 comments on commit 0ef9351

Please sign in to comment.