feat: init SwiftUI library for FirebaseAuthSwiftUI#1237
feat: init SwiftUI library for FirebaseAuthSwiftUI#1237russellwheatley merged 216 commits intomainfrom
Conversation
morganchen12
left a comment
There was a problem hiding this comment.
Overall looks good. Had one architecture question for consideration.
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/FirebaseAuthSwiftUI/FirebaseAuthSwiftUI.swift
Outdated
Show resolved
Hide resolved
morganchen12
left a comment
There was a problem hiding this comment.
Everything that's marked TODO can be done in a future PR.
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift
Outdated
Show resolved
Hide resolved
FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Views/GoogleButtonView.swift
Outdated
Show resolved
Hide resolved
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthConfiguration.swift
Outdated
Show resolved
Hide resolved
FirebaseSwiftUI/FirebaseGoogleSwiftUI/Sources/Services/GoogleProviderSwift.swift
Outdated
Show resolved
Hide resolved
FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Services/AuthService.swift
Outdated
Show resolved
Hide resolved
FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Utils/FacebookUtils.swift
Outdated
Show resolved
Hide resolved
|
|
||
| public init() {} | ||
|
|
||
| private var limitedLoginBinding: Binding<Bool> { |
There was a problem hiding this comment.
This computed property does a lot. It is trying to sync with ATTrackingManager.trackingAuthorizationStatus, and also drives showUserTrackingAlert and limitedLogin.
We should simplify this.
There was a problem hiding this comment.
Here is an alternative solution that feels cleaner:
@State private var showUserTrackingAlert = false
@State private var trackingAuthorizationStatus: ATTrackingManager.AuthorizationStatus = .notDetermined
var isLimitedLogin: Bool {
trackingAuthorizationStatus != .authorized
}
public init() {
_trackingAuthorizationStatus = State(initialValue: ATTrackingManager.trackingAuthorizationStatus)
}
func requestTrackingPermission() {
ATTrackingManager.requestTrackingAuthorization { status in
Task { @MainActor in
trackingAuthorizationStatus = status
if status != .authorized {
showUserTrackingAlert = true
}
}
}
}
There was a problem hiding this comment.
updated to reduce scope of binding: 0d5d8ba (#1237)
Not sure if you agree but a binding was still needed to stop toggle from switching if limited login wasn't possible.
FirebaseSwiftUI/FirebaseFacebookSwiftUI/Sources/Views/FacebookButtonView.swift
Outdated
Show resolved
Hide resolved
| func deleteUser() async throws { | ||
| do { | ||
| if let user = auth.currentUser, let lastSignInDate = user.metadata.lastSignInDate { | ||
| let needsReauth = !lastSignInDate.isWithinPast(minutes: 5) |
There was a problem hiding this comment.
Instead of making assumptions about the grace period, it'd be better to make the call and handle the error.
There was a problem hiding this comment.
Thanks for that, that's a much cleaner approach so I have leaned heavily on it and will use that for reauthenticate operations for other providers. I have tweaked it slightly by keeping it swiftui and removing the password prompt via UIKit:
peterfriese
left a comment
There was a problem hiding this comment.
Looking good. I left a few comments, happy for you do address them in a follow-up PR.
I'd also like to see the following:
- Previews for all views. At the moment, it's not possible to preview the views, which makes it difficult to judge the design.
- Package.swift files for the individual modules (to support (1))
Approved provided my remarks are addressed in follow-up PRs.
| } | ||
| } | ||
|
|
||
| struct ContentView: View { |
There was a problem hiding this comment.
TODO: please move the ContentView into a separate file to make it easier to find.
| }.padding(.vertical, 6) | ||
| .background(Divider(), alignment: .bottom) | ||
| .padding(.bottom, 4) | ||
| Button(action: { |
There was a problem hiding this comment.
TODO:
Nit: I would prefer the following signature (here, and in general):
Button {
} label: {
}| } else { | ||
| Text(authService.authenticationFlow == .login ? "Login" : "Sign up") | ||
| VStack { Divider() } | ||
| EmailAuthView() |
There was a problem hiding this comment.
So this means that we'll always have Email/Password be the most prominent provider. I would advocate to allow users to instantiate EmailAuthView themselves via the providerButtons closure.
- I think we should no longer promote Email/Password as the go-to auth provider. Passwords are inherently insecure, and we should promote more secure providers instead.
- This gives developers more flexibility (e.g. put SiwA / SiwG first, and Email last)
| case user(String) | ||
| } | ||
|
|
||
| public class GoogleProviderSwift: @preconcurrency GoogleProviderProtocol { |
There was a problem hiding this comment.
I'm not super happy with the Swift suffix. Also, can we include Auth in the name? Same for the protocol(s).
This applies to all providers.
|
Thanks, @peterfriese. Now the last bits of feedback have been resolved, and as discussed in the last meeting, I will merge this PR. I'll follow up with the further suggestions you've made with the exception of email/password View update. This is on hold until we have finalised solution for using View modifiers (See this PR). But I think we're all in agreement, users should be able to decide if they want email/password auth which will be opted-in (i.e. something like |
Work in progress