Skip to content

Commit 0bd8ff6

Browse files
authored
fix(Auth): Handling proper error when attempting to change password fails due to an expired session. (#1995)
1 parent 78ee0c8 commit 0bd8ff6

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Dependency/AuthUserServiceAdapter.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,31 @@ class AuthUserServiceAdapter: AuthUserServiceBehavior {
146146
completionHandler(.success(()))
147147
return
148148
}
149-
if let awsMobileClientError = error as? AWSMobileClientError,
150-
case .notSignedIn = awsMobileClientError {
151-
let authError = AuthError.signedOut(
152-
AuthPluginErrorConstants.changePasswordSignedOutError.errorDescription,
153-
AuthPluginErrorConstants.changePasswordSignedOutError.recoverySuggestion, nil)
154-
completionHandler(.failure(authError))
155-
} else {
149+
150+
guard let awsMobileClientError = error as? AWSMobileClientError else {
156151
let authError = AuthErrorHelper.toAuthError(error)
157152
completionHandler(.failure(authError))
153+
return
154+
}
155+
156+
let authError: AuthError
157+
switch awsMobileClientError {
158+
case .notSignedIn:
159+
authError = AuthError.signedOut(
160+
AuthPluginErrorConstants.changePasswordSignedOutError.errorDescription,
161+
AuthPluginErrorConstants.changePasswordSignedOutError.recoverySuggestion,
162+
nil
163+
)
164+
case .unableToSignIn:
165+
authError = AuthError.sessionExpired(
166+
AuthPluginErrorConstants.changePasswordUnableToSignInError.errorDescription,
167+
AuthPluginErrorConstants.changePasswordUnableToSignInError.recoverySuggestion,
168+
nil
169+
)
170+
default:
171+
authError = AuthErrorHelper.toAuthError(error)
158172
}
173+
completionHandler(.failure(authError))
159174
}
160175

161176
}

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ struct AuthPluginErrorConstants {
139139
static let changePasswordSignedOutError: AuthPluginErrorString = (
140140
"Could not change password, there is no user signed in to the Auth category",
141141
"Change password require a user signed in to Auth category, use one of the signIn apis to signIn")
142+
143+
static let changePasswordUnableToSignInError: AuthPluginErrorString = (
144+
"Could not change password, the user session is expired",
145+
"Re-authenticate the user by using one of the signIn apis")
142146
}
143147

144148
// Field validation errors

0 commit comments

Comments
 (0)