StanfordSpezi / SpeziAccount

The Spezi Account module to enable login and signup functionality
https://swiftpackageindex.com/StanfordSpezi/SpeziAccount/documentation/
MIT License
5 stars 5 forks source link

Model Account Service as singleton with ability to provide multiple Identity Providers #62

Closed Supereg closed 4 weeks ago

Supereg commented 1 month ago

Model Account Service as singleton with ability to provide multiple Identity Providers

:recycle: Current situation & Problems

The current design of SpeziAccount allows to have multiple AccountServices that each implement exactly one identity provider (e.g., signup with password credentials or SSO using Sign in with Apple). We are currently missing support for a single AccountService to combine multiple identity providers. Secondly, we found that there is generally no need for an application to support multiple, entirely different account services.

Further, the current infrastructure is relatively strict on how to define account services and their UI components. This is done through multiple different sub-protocols to the based AccountService protocol. Each protocol makes certain assumptions how an account service might look and is, therefore, (magically) providing certain default implementations or default UI components. While the defaults are great, we found that this design is pretty inflexible. If an account service doesn't quite fit the requirements of one of the default protocols, it has to implement a lot of the things completely from scratch. Most of the default UI components shipped with SpeziAccount are tightly coupled with these protocols and can therefore not be easily reused. We would love a design that provides great defaults, but not at the cost of flexibility.

Further, account notifications and external storage are currently realized using Standard constraints. Specifically with external storage we found that these are often provided by external components and that the constraint was always just used to forward the implementation to such a component. Removing the constraint and directly supplying the external storage provider to the AccountConfiguration would be much more ideal. In an attempt to transparently support notifications and external storage, internal wrapper account services were used to automatically implement support for these operations. This design required several workarounds when it was required to interact with the underlying account service and was easy to get wrong. Not ideal.

Lastly, there was typically a lot of boiler plate code required to create new account keys, making it a bigger effort than necessary. Notably, creating non-String-based account keys involved creating display and entry view components as there wasn't anything provided out of the box for most primitive types. All in all, it made fast prototyping harder as considerable effort had to be spent when implementing new account keys.

The release notes sections lists how all of these problems have been addressed in this PR.

:gear: Release Notes

:books: Documentation

The documentation catalog was restructured. Generally, nesting was reduced and it aims to move types that are relevant to framework users to the root documentation page to make it more easily navigable and discoverable. Documentation that is tailored towards developers implementing account services or external storage providers got their own group. Generally, all documentation was updated to reflect the new functionality.

:white_check_mark: Testing

Existing tests were used to verify existing behavior. Some new tests were added to tests new functionalities.

:pencil: Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 83.74628% with 492 lines in your changes missing coverage. Please review.

Project coverage is 84.44%. Comparing base (e3344aa) to head (3a54f5d). Report is 1 commits behind head on main.

Files Patch % Lines
...ountValue/Collections/AccountDetails+Codable.swift 67.34% 49 Missing :warning:
...ces/SpeziAccount/Mock/InMemoryAccountService.swift 89.55% 39 Missing :warning:
...untSetup/SetupProvider/SignInWithAppleButton.swift 39.07% 39 Missing :warning:
...ount/AccountValue/Collections/AccountDetails.swift 74.65% 36 Missing :warning:
...countValue/Collections/AccountDetailsBuilder.swift 66.22% 25 Missing :warning:
...Account/Environment/SignupProviderCompliance.swift 48.98% 25 Missing :warning:
Sources/SpeziAccount/ExternalAccountStorage.swift 70.13% 23 Missing :warning:
...eziAccount/AccountValue/Keys/EmailAddressKey.swift 53.34% 14 Missing :warning:
...ccount/AccountValue/Keys/AccountDetailsFlags.swift 75.52% 12 Missing :warning:
...ountSetup/SetupProvider/AccountServiceButton.swift 72.10% 12 Missing :warning:
... and 47 more
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62/graphs/tree.svg?width=650&height=150&src=pr&token=AudNwGU7tR&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi)](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) ```diff @@ Coverage Diff @@ ## main #62 +/- ## ========================================== + Coverage 0.00% 84.44% +84.44% ========================================== Files 115 120 +5 Lines 4065 5204 +1139 ========================================== + Hits 0 4394 +4394 + Misses 4065 810 -3255 ``` | [Files](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | Coverage Δ | | |---|---|---| | [Sources/SpeziAccount/AccountHeader.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountHeader.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudEhlYWRlci5zd2lmdA==) | `92.31% <100.00%> (+92.31%)` | :arrow_up: | | [...s/SpeziAccount/AccountService/AccountService.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FAccountService.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQWNjb3VudFNlcnZpY2Uuc3dpZnQ=) | `0.00% <ø> (ø)` | | | [...ce/Configuration/AccountServiceConfiguration.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FConfiguration%2FAccountServiceConfiguration.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQ29uZmlndXJhdGlvbi9BY2NvdW50U2VydmljZUNvbmZpZ3VyYXRpb24uc3dpZnQ=) | `100.00% <100.00%> (+100.00%)` | :arrow_up: | | [...ntService/Configuration/FieldValidationRules.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FConfiguration%2FFieldValidationRules.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQ29uZmlndXJhdGlvbi9GaWVsZFZhbGlkYXRpb25SdWxlcy5zd2lmdA==) | `70.28% <100.00%> (+70.28%)` | :arrow_up: | | [...ntService/Configuration/SupportedAccountKeys.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FConfiguration%2FSupportedAccountKeys.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQ29uZmlndXJhdGlvbi9TdXBwb3J0ZWRBY2NvdW50S2V5cy5zd2lmdA==) | `93.34% <100.00%> (+93.34%)` | :arrow_up: | | [...untService/Configuration/UserIdConfiguration.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FConfiguration%2FUserIdConfiguration.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQ29uZmlndXJhdGlvbi9Vc2VySWRDb25maWd1cmF0aW9uLnN3aWZ0) | `100.00% <100.00%> (+100.00%)` | :arrow_up: | | [...ount/AccountService/Configuration/UserIdType.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountService%2FConfiguration%2FUserIdType.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFNlcnZpY2UvQ29uZmlndXJhdGlvbi9Vc2VySWRUeXBlLnN3aWZ0) | `80.00% <ø> (+80.00%)` | :arrow_up: | | [Sources/SpeziAccount/AccountStorageProvider.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountStorageProvider.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFN0b3JhZ2VQcm92aWRlci5zd2lmdA==) | `100.00% <100.00%> (ø)` | | | [...s/SpeziAccount/AccountValue/AccountKey+Views.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountValue%2FAccountKey%2BViews.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFZhbHVlL0FjY291bnRLZXkrVmlld3Muc3dpZnQ=) | `100.00% <100.00%> (+100.00%)` | :arrow_up: | | [...SpeziAccount/AccountValue/AccountKeyCategory.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree&filepath=Sources%2FSpeziAccount%2FAccountValue%2FAccountKeyCategory.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aUFjY291bnQvQWNjb3VudFZhbHVlL0FjY291bnRLZXlDYXRlZ29yeS5zd2lmdA==) | `80.00% <ø> (+80.00%)` | :arrow_up: | | ... and [94 more](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | | ... and [16 files with indirect coverage changes](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Last update [e3344aa...3a54f5d](https://app.codecov.io/gh/StanfordSpezi/SpeziAccount/pull/62?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi).
Supereg commented 1 month ago

@PSchmiedmayer markdown lint is currently failing as we are linking to the FirebaseAccountService that is not yet deployed in the documentation catalog.

PSchmiedmayer commented 3 weeks ago

Great job to get this merged @Supereg; a huge lift!