@@ -110,8 +110,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
110110 func deleteAuth( _ uid: String ) async throws {
111111 do {
112112 logger. info ( " Deleting Apple grant for user: \( uid) " )
113- let response = try await FunctionAPIClient . shared. send ( . revokeAppleAccessToken)
114- try validate ( response)
113+ try await FunctionAPIClient . shared. send ( . revokeAppleAccessToken)
115114 } catch {
116115 logger. error ( " Failed to delete Apple auth " , error: error)
117116 record ( error, code: . deleteAuth)
@@ -125,15 +124,14 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
125124 let challenge = try await requestAppleChallenge ( )
126125 let response = try await authenticateWithAppleAsync ( hashedNonce: challenge. hashedNonce)
127126
128- let operation = try await FunctionAPIClient . shared. send (
127+ try await FunctionAPIClient . shared. send (
129128 . linkAppleAccount,
130129 payload: AppleAccountLinkRequest (
131130 challengeId: challenge. challengeId,
132131 authorizationCode: response. authorizationCode,
133132 credentialEmail: response. email
134133 )
135134 )
136- try validate ( operation)
137135 try await user? . reload ( )
138136 return true
139137 } catch {
@@ -149,8 +147,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
149147 func unlink( _ uid: String ) async throws {
150148 do {
151149 logger. info ( " Unlinking Apple account for user: \( uid) " )
152- let response = try await FunctionAPIClient . shared. send ( . unlinkAppleAccount)
153- try validate ( response)
150+ try await FunctionAPIClient . shared. send ( . unlinkAppleAccount)
154151 try await user? . reload ( )
155152 } catch {
156153 let mappedError = mapAppleAPIError ( error)
@@ -243,22 +240,18 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
243240}
244241
245242private extension AppleAuthenticationServiceImpl {
246- func validate( _ response: AppleOperationResponse ) throws {
247- guard response. success else {
248- throw TokenError . invalidResponse
249- }
250- }
251-
252243 func mapAppleAPIError( _ error: Error ) -> Error {
253244 if let emailError = error. apiEmailError {
254245 return emailError
255246 }
256247
248+ if error. apiAuthenticationError == . lastProvider {
249+ return DataLayerError . failedToUnlinkLastProvider
250+ }
251+
257252 switch error. apiAppleAuthenticationError {
258253 case . providerLinkConflict:
259254 return DataLayerError . linkCredentialAlreadyInUse
260- case . lastProvider:
261- return DataLayerError . failedToUnlinkLastProvider
262255 case . none:
263256 return error
264257 }
0 commit comments