Skip to content

Instantly share code, notes, and snippets.

@gahntpo
Last active June 21, 2020 08:39
Show Gist options
  • Save gahntpo/3c9f3bd0c001b1b1813343696c224bc7 to your computer and use it in GitHub Desktop.
Save gahntpo/3c9f3bd0c001b1b1813343696c224bc7 to your computer and use it in GitHub Desktop.
changing the ui when the use logs in/out
import Foundation
import Combine
class NavigationAuthController: ObservableObject {
@Published var selection: Int = 1
@Published var detailIsShown: Bool = false
@Published var alertIsShown: Bool = false
var subscriptions = Set<AnyCancellable>()
init() {
AuthSubscriptionManager.shared.$firebaseUser
.removeDuplicates()
.sink { (user) in
print("--- new user -- close open docs")
self.resetAll()
}.store(in: &subscriptions)
}
func resetAll() {
self.selection = 0
self.detailIsShown = false
self.alertIsShown = false
}
}
//using singelton to have one Authentication instance for all open windows
import FirebaseAuth
class AuthSubscriptionManager: NSObject, ObservableObject {
static let shared = AuthSubscriptionManager()
@Published var firebaseUser: User?
init() {
//do Firebase init and login
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment