Skip to content

Commit a516f62

Browse files
authored
chore(auth): improved error handling for userNotFound error when fetching a signed in session (#1605)
1 parent 3209874 commit a516f62

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Dependency/AuthorizationProviderAdapter+SignedInSession.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension AuthorizationProviderAdapter {
5858
self.fetchSignedInSession(withError: AuthErrorHelper.toAuthError(error!),
5959
completionHandler)
6060
}
61-
} else if (error as NSError?)?.userInfo["__type"] as? String == "UserNotFoundException" {
61+
} else if self.isErrorCausedByUserNotFound(error) {
6262
self.awsMobileClient.signOutLocally()
6363
self.fetchSignedOutSession(completionHandler)
6464
Amplify.Hub.dispatch(to: .auth, payload: HubPayload(eventName: HubPayload.EventName.Auth.signedOut))
@@ -252,4 +252,13 @@ extension AuthorizationProviderAdapter {
252252
}
253253
return false
254254
}
255+
256+
private func isErrorCausedByUserNotFound(_ error: Error?) -> Bool {
257+
if let cognitoIdentityProviderError = error as NSError?,
258+
cognitoIdentityProviderError.domain == AWSCognitoIdentityProviderErrorDomain,
259+
cognitoIdentityProviderError.code == AWSCognitoIdentityProviderErrorType.userNotFound.rawValue {
260+
return true
261+
}
262+
return false
263+
}
255264
}

0 commit comments

Comments
 (0)