bmcmahen / julienne-swift

An iOS port of Julienne.app, built with SwiftUI and Firebase
51 stars 14 forks source link

Google Sign In #1

Open kinergy opened 4 years ago

kinergy commented 4 years ago

Hi, thank you for the awesome tutorial and sample code! Any chance you could help me figure out how to extend your sample code to support Google Sign In? Would you recommend trying to integrate FirebaseUI or do it directly?

Patrick3131 commented 4 years ago

@kinergy do you still need help?

Patrick3131 commented 4 years ago

In case you still need it:

here a solution based on the FirebaseUI and UIViewControllerRepresentable:

struct FUIAuthBaseViewControllerWrapper: UIViewControllerRepresentable {

    typealias UIViewControllerType = UIViewController

    func makeUIViewController(context: UIViewControllerRepresentableContext<FUIAuthBaseViewControllerWrapper>) -> UIViewController {
         let authUI = FUIAuth.defaultAuthUI()
//               authUI?.delegate = self

               let providers = [FUIEmailAuth()]
               authUI?.providers = providers
        let authViewController = (authUI?.authViewController())!
        return authViewController
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<FUIAuthBaseViewControllerWrapper>) {

    }
}

Just add the google provider in providers.

As a LoginView just use it like this:

struct LoginView: View {
    var body: some View {
        FUIAuthBaseViewControllerWrapper()
    }
}
struct TabBarView: View {
    @EnvironmentObject var sessionStore: SessionStore
    @State private var selectedTab = Tab.swiping

    enum Tab: Int {
        case swiping, matches, profil
    }

    var body: some View {
        Group {
            if (sessionStore.session != nil) {
                         TabView(selection: $selectedTab) {
                            SwipingView().tabItem {
                                TabBarItem(text: "Text", image: "pause.circle")
                            }.tag(Tab.swiping)
                        }
                    } else {
                        LoginView()
                    }
        }.onAppear(perform: sessionStore.listen).onDisappear(perform: sessionStore.stopListen)
    }
}