-
Notifications
You must be signed in to change notification settings - Fork 484
README for SwiftUI alpha release #1251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a2b2b34
README for SwiftUI alpha release
russellwheatley dc02732
format
russellwheatley 15107ed
format
russellwheatley d30af1c
chore: address PR feedback; spelling and formatting code snippet
russellwheatley b20de63
chore: grammar correction
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# FirebaseUI for SwiftUI (Alpha release) | ||
|
||
## Installation | ||
|
||
1. Launch Xcode and open the project or workspace where you want to add the packages. | ||
2. In the menu bar, go to: `File > Add Package Dependencies...` | ||
3. Enter the Package URL: `https://github.com/firebase/FirebaseUI-iOS` | ||
4. Select target(s) you wish to add to your app (currently `FirebaseAuthSwiftUI`, `FirebaseGoogleSwiftUI`, `FirebaseFacebookSwiftUI` and `FirebasePhoneAuthSwiftUI` are available). `FirebaseAuthSwiftUI` is required and contains the Email provider API. | ||
5. Press the `Add Packages` button to complete installation. | ||
|
||
|
||
## Getting started | ||
|
||
1. Follow step 2, 3 & 5 on [adding Firebase to your SwiftUI app](https://firebase.google.com/docs/ios/setup). | ||
2. You should now update your app entry point to look like this: | ||
|
||
```swift | ||
import FirebaseAuthSwiftUI | ||
import FirebaseCore | ||
import SwiftUI | ||
|
||
class AppDelegate: NSObject, UIApplicationDelegate { | ||
func application(_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [ | ||
UIApplication.LaunchOptionsKey: Any | ||
]?) -> Bool { | ||
FirebaseApp.configure() | ||
return true | ||
} | ||
} | ||
|
||
@main | ||
struct FirebaseSwiftUIExampleApp: App { | ||
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} | ||
|
||
struct ContentView: View { | ||
let authService: AuthService | ||
|
||
init() { | ||
let configuration = AuthConfiguration() | ||
|
||
authService = AuthService( | ||
configuration: configuration, | ||
) | ||
.withEmailSignIn() | ||
} | ||
|
||
var body: some View { | ||
AuthPickerView().environment(authService) | ||
} | ||
} | ||
``` | ||
|
||
3. For a more complete example, see the [SwiftUI sample app](https://github.com/firebase/FirebaseUI-iOS/tree/main/samples/swiftui/FirebaseSwiftUIExample). | ||
|
||
## Configuration options | ||
|
||
You can create an `AuthConfiguration` instance and pass it to the `AuthService` as demonstrated above. Here are the options: | ||
|
||
```swift | ||
public struct AuthConfiguration { | ||
// hides cancel buttons when you don't want a flow to be interrupted | ||
let shouldHideCancelButton: Bool | ||
// stop users from being able to swipe away sheets/modal | ||
let interactiveDismissEnabled: Bool | ||
// automatically upgrade anonymous users so that they are linked with account being used to sign-in | ||
let shouldAutoUpgradeAnonymousUsers: Bool | ||
// custom string bundle for string localizations | ||
let customStringsBundle: Bundle? | ||
// terms of service URL | ||
let tosUrl: URL | ||
// privacy policy URL | ||
let privacyPolicyUrl: URL | ||
// action code settings for email sign in link | ||
let emailLinkSignInActionCodeSettings: ActionCodeSettings? | ||
// action code settings verifying email address | ||
let verifyEmailActionCodeSettings: ActionCodeSettings? | ||
|
||
public init(shouldHideCancelButton: Bool = false, | ||
interactiveDismissEnabled: Bool = true, | ||
shouldAutoUpgradeAnonymousUsers: Bool = false, | ||
customStringsBundle: Bundle? = nil, | ||
tosUrl: URL = URL(string: "https://example.com/tos")!, | ||
privacyPolicyUrl: URL = URL(string: "https://example.com/privacy")!, | ||
emailLinkSignInActionCodeSettings: ActionCodeSettings? = nil, | ||
verifyEmailActionCodeSettings: ActionCodeSettings? = nil) | ||
} | ||
``` | ||
|
||
## Configuring providers | ||
|
||
1. Ensure the provider is installed from step 1 (e.g. if configuring Google provider, you need to install `FirebaseGoogleSwiftUI` package). | ||
2. Ensure you have called the relevant API on `AuthService` to initialise the provider. Example of Email and Google provider initialization: | ||
|
||
```swift | ||
let authService = AuthService() | ||
.withEmailSignIn() | ||
.withGoogleSignIn() | ||
``` | ||
|
||
> Note: There may be additional setup for each provider typically in the AppDelegate. [See example app for setup.](https://github.com/firebase/FirebaseUI-iOS/tree/main/samples/swiftui/FirebaseSwiftUIExample) | ||
|
||
|
||
## API available for alpha release | ||
1. General API | ||
- Auto upgrade anonymous user account linking (if configured). | ||
- Sign out | ||
2. Email/Password | ||
- Sign-in/Create user | ||
- Password recovery | ||
- Email link sign-in | ||
3. Google | ||
- Sign in with Google | ||
4. Facebook | ||
1. Sign in with Facebook limited login | ||
2. Sign in with Facebook classic login | ||
5. Phone Auth | ||
- Verify phone number | ||
- Sign in with phone number | ||
6. User | ||
- Update password | ||
- Delete user | ||
- Verify email address | ||
|
||
|
||
## Notes for Alpha release | ||
1. Customization/theming for Views is not yet available. | ||
2. The providers available are Email, Phone, Google and Facebook. | ||
3. String localizations have been ported over and used where possible from the previous implementation, but new strings will only have English translations for the time being. | ||
4. The UI has not been polished and is subject to change once design has been finalized. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these parameters shouldn't have default values, or should be nullable. It would be an error to ship your app with these default values.
(This can be addressed in a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I think nullable is right. I'll address in separate PR.