RxFirebase-Deprecated
RxFirebase-Deprecated copied to clipboard
Should we include this kind of functionality?
Hello All,
I one of my projects I used a master class to handle all Firebase+Rx interactions and receive GIDAuthentication info from a separate Google class that handles all Google Sign In stuff.
Is this somehting that we want to have? I can make a more-documented proposal.
class Firebase {
static let instance = Firebase()
internal let rx_user = ReplaySubject<FIRUser>.create(bufferSize: 1)
internal let disposeBag = DisposeBag()
private let database = FIRDatabase.database().reference()
private let storage = FIRStorage.storage().reference()
// this prevents others from using the
// default '()' initializer for this class.
private init() {
// pass firebase clientID to Google
if let clientID = clientID {
Google.instance.clientID = clientID
}
// new user chain
Google.instance
.rx_firebaseCredential
.flatMapLatest { credential in
Firebase.instance.rx_signInWithCredential(credential)
}
.subscribeNext({ user in
Firebase.instance.rx_user.onNext(user)
})
.addDisposableTo(Google.instance.disposeBag)
}
class Google : NSObject, GIDSignInDelegate, GIDSignInUIDelegate {
static let instance = Google()
internal let disposeBag = DisposeBag()
var rx_firebaseCredential : Observable<FIRAuthCredential> {
return rx_user
.doOnNext({ _ in print("--------------- rx_firebaseCredential received") })
.map({ $0.authentication })
.map({ authentication in
FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
accessToken: authentication.accessToken)
})
}
private let rx_user = ReplaySubject<GIDGoogleUser>.create(bufferSize: 1)
}