Skip to content

Commit

Permalink
Ensure name is updated after anonymous account linking
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jun 11, 2024
1 parent f05c859 commit faef99a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ extension FirebaseAccountService {
}

if let name = modifications.modifiedDetails.name {
Self.logger.debug("Creating change request for updated display name.")
let changeRequest = currentUser.createProfileChangeRequest()
changeRequest.displayName = name.formatted(.name(style: .long))
try await changeRequest.commitChanges()
try await updateDisplayName(of: currentUser, name)
}

// None of the above requests will trigger our state change listener, therefore, we just call it manually.
Expand All @@ -129,4 +126,11 @@ extension FirebaseAccountService {
throw FirebaseAccountError.unknown(.internalError)
}
}

func updateDisplayName(of user: User, _ name: PersonNameComponents) async throws {
Self.logger.debug("Creating change request for updated display name.")
let changeRequest = user.createProfileChangeRequest()
changeRequest.displayName = name.formatted(.name(style: .long))
try await changeRequest.commitChanges()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ actor FirebaseEmailPasswordAccountService: UserIdPasswordAccountService, Firebas
Self.logger.debug("Linking email-password credentials with current anonymous user account ...")
let result = try await currentUser.link(with: credential)

Check warning on line 94 in Sources/SpeziFirebaseAccount/Account Services/FirebaseEmailPasswordAccountService.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package / Test using xcodebuild or run fastlane

initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 94 in Sources/SpeziFirebaseAccount/Account Services/FirebaseEmailPasswordAccountService.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests / Test using xcodebuild or run fastlane

initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it

if let displayName = signupDetails.name {
try await updateDisplayName(of: currentUser, displayName)
}

try await context.notifyUserSignIn(user: currentUser, for: self, isNewUser: true)

return
Expand All @@ -105,10 +109,7 @@ actor FirebaseEmailPasswordAccountService: UserIdPasswordAccountService, Firebas
try await authResult.user.sendEmailVerification()

if let displayName = signupDetails.name {
Self.logger.debug("Creating change request for display name.")
let changeRequest = authResult.user.createProfileChangeRequest()
changeRequest.displayName = displayName.formatted(.name(style: .medium))
try await changeRequest.commitChanges()
try await updateDisplayName(of: authResult.user, displayName)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/UITests/TestAppUITests/FirebaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct FirestoreAccount: Decodable, Equatable {


enum FirebaseClient {
private static let projectId = "spezifirebaseuitests"
private static let projectId = "nams-e43ed"

// curl -H "Authorization: Bearer owner" -X DELETE http://localhost:9099/emulator/v1/projects/spezifirebaseuitests/accounts
static func deleteAllAccounts() async throws {
Expand Down

0 comments on commit faef99a

Please sign in to comment.