From 0fb003b5562f5028a65d7a1c581441d559dbd600 Mon Sep 17 00:00:00 2001 From: talksik Date: Tue, 14 Dec 2021 14:49:17 -0800 Subject: [PATCH] getting some things working with navigation and auth but not updating environment variable yet --- nirvana-ios/ContentView.swift | 19 +++---- nirvana-ios/Views/SignIn/SignInView.swift | 55 +------------------ nirvana-ios/Views/Templates/HeaderView.swift | 2 - .../Views/WelcomeView/WelcomeView.swift | 52 +++++++++--------- nirvana-ios/nirvana_iosApp.swift | 21 +++---- 5 files changed, 43 insertions(+), 106 deletions(-) diff --git a/nirvana-ios/ContentView.swift b/nirvana-ios/ContentView.swift index 4e8eff1..10d787a 100644 --- a/nirvana-ios/ContentView.swift +++ b/nirvana-ios/ContentView.swift @@ -11,18 +11,13 @@ struct ContentView: View { @EnvironmentObject var authSessionStore: AuthSessionStore var body: some View { - NavigationView { - ZStack { - switch self.authSessionStore.sessionState { - case SessionState.isAuthenticated: - HomeView() - case SessionState.isLoggedOut: - WelcomeView() - } -// NavigationLink("Welcome Page", isActive: self.authSessionStore.sessionState == SessionState.isLoggedOut, WelcomeView()) -// NavigationLink("HomePage", isActive: self.authSessionStore.sessionState == SessionState.isAuthenticated, destination: HomeView()) - - }.navigationBarHidden(true) + ZStack { + switch self.authSessionStore.sessionState { + case SessionState.isAuthenticated: + HomeView() + case SessionState.isLoggedOut: + WelcomeView() + } } } } diff --git a/nirvana-ios/Views/SignIn/SignInView.swift b/nirvana-ios/Views/SignIn/SignInView.swift index 491f045..b8568c6 100644 --- a/nirvana-ios/Views/SignIn/SignInView.swift +++ b/nirvana-ios/Views/SignIn/SignInView.swift @@ -64,49 +64,8 @@ struct SignInView: View { } func handleLogin() { - //Google sign in - guard let clientID = FirebaseApp.app()?.options.clientID else { return } - - // create google sign in configuration object - let config = GIDConfiguration(clientID: clientID) - - GIDSignIn.sharedInstance.signIn(with: config, presenting: getRootViewController()) - {[self] user, err in - - if err != nil { - print(err!.localizedDescription) - return - } - - guard - let authentication = user?.authentication, - let idToken = authentication.idToken - else { - return - } - - let credential = GoogleAuthProvider.credential(withIDToken: idToken, - accessToken: authentication.accessToken) - - Auth.auth().signIn(with: credential) { result, error in - if error != nil { - print(error!.localizedDescription) - } - - guard let user = result?.user else { - return - } - - print(user.displayName ?? "Success!") - print(user) - // User is signed in - // ... - } - } + self.authSessionStore.signInOrCreateUser() } - - - } struct SignInView_Previews: PreviewProvider { @@ -114,15 +73,3 @@ struct SignInView_Previews: PreviewProvider { SignInView().environmentObject(AuthSessionStore()) } } - -extension View { - func getRootViewController() -> UIViewController { - guard let screen = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return .init() } - - guard let root = screen.windows.first?.rootViewController else { - return .init() - } - - return root - } -} diff --git a/nirvana-ios/Views/Templates/HeaderView.swift b/nirvana-ios/Views/Templates/HeaderView.swift index a4e4de4..472e158 100644 --- a/nirvana-ios/Views/Templates/HeaderView.swift +++ b/nirvana-ios/Views/Templates/HeaderView.swift @@ -21,7 +21,6 @@ struct HeaderView: View { .font(Font.system(.largeTitle)) .padding() .foregroundColor(NirvanaColor.teal) - } Spacer() @@ -45,7 +44,6 @@ struct HeaderView: View { .padding() .foregroundColor(NirvanaColor.teal) } - } .frame(maxWidth: .infinity) } diff --git a/nirvana-ios/Views/WelcomeView/WelcomeView.swift b/nirvana-ios/Views/WelcomeView/WelcomeView.swift index 8921e2b..5b48ba3 100644 --- a/nirvana-ios/Views/WelcomeView/WelcomeView.swift +++ b/nirvana-ios/Views/WelcomeView/WelcomeView.swift @@ -8,37 +8,37 @@ import SwiftUI struct WelcomeView: View { - let screenWidth = UIScreen.main.bounds.width - let screenHeight = UIScreen.main.bounds.height - var body: some View { + NavigationView { OnboardingTemplateView(imgName: "undraw_friendship_mni7", mainLeadingActText: "Your", mainHighlightedActText: "minimalist", mainTrailingActText: "social media.", subActText: "Tired of the rat race on insta, snap, tik-tok, \"meta\"?", bottomActArea: AnyView( - VStack(alignment: .center) { - NavigationLink(destination: SignInView()) { - Text("Start Your Detox") - .bold() - .foregroundColor(NirvanaColor.white) - .frame(maxWidth: .infinity) - .padding(.vertical, 20) - .background(NirvanaColor.teal) - .clipShape(Capsule()) - .shadow(radius:10) - } - - Button( - action: { - print("link to website learn more clicked") - }, - label: { - Text("Learn More") + VStack(alignment: .center) { + NavigationLink(destination: SignInView()) { + Text("Start Your Detox") .bold() - }) + .foregroundColor(NirvanaColor.white) + .frame(maxWidth: .infinity) + .padding(.vertical, 20) + .background(NirvanaColor.teal) + .clipShape(Capsule()) + .shadow(radius:10) + } + + Button( + action: { + print("link to website learn more clicked") + }, + label: { + Text("Learn More") + .bold() + }) - //learn more button to usenirvana.com - } - .padding(.top, 20) - ) + //learn more button to usenirvana.com + } + .padding(.top, 20) + ) ) + .navigationBarHidden(true) + } // navigation view } // View body } // View diff --git a/nirvana-ios/nirvana_iosApp.swift b/nirvana-ios/nirvana_iosApp.swift index 06b4a23..755cf84 100644 --- a/nirvana-ios/nirvana_iosApp.swift +++ b/nirvana-ios/nirvana_iosApp.swift @@ -13,22 +13,19 @@ import GoogleSignIn struct nirvana_iosApp: App { @StateObject var authSessionStore: AuthSessionStore = AuthSessionStore() - @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate - var body: some Scene { + init() { + self.setupAuth() + } + + var body: some Scene { WindowGroup { ContentView().environmentObject(authSessionStore) } - } + } } - -class AppDelegate: NSObject, UIApplicationDelegate { - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { - FirebaseApp.configure() - return true - } - - func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool { - return GIDSignIn.sharedInstance.handle(url) +extension nirvana_iosApp { + private func setupAuth() { + FirebaseApp.configure() } }