getting some things working with navigation and auth but not updating environment variable yet

This commit is contained in:
talksik
2021-12-14 14:49:17 -08:00
parent f321e983b2
commit 0fb003b556
5 changed files with 43 additions and 106 deletions
+7 -12
View File
@@ -11,18 +11,13 @@ struct ContentView: View {
@EnvironmentObject var authSessionStore: AuthSessionStore @EnvironmentObject var authSessionStore: AuthSessionStore
var body: some View { var body: some View {
NavigationView { ZStack {
ZStack { switch self.authSessionStore.sessionState {
switch self.authSessionStore.sessionState { case SessionState.isAuthenticated:
case SessionState.isAuthenticated: HomeView()
HomeView() case SessionState.isLoggedOut:
case SessionState.isLoggedOut: WelcomeView()
WelcomeView() }
}
// NavigationLink("Welcome Page", isActive: self.authSessionStore.sessionState == SessionState.isLoggedOut, WelcomeView())
// NavigationLink("HomePage", isActive: self.authSessionStore.sessionState == SessionState.isAuthenticated, destination: HomeView())
}.navigationBarHidden(true)
} }
} }
} }
+1 -54
View File
@@ -64,49 +64,8 @@ struct SignInView: View {
} }
func handleLogin() { func handleLogin() {
//Google sign in self.authSessionStore.signInOrCreateUser()
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
// ...
}
}
} }
} }
struct SignInView_Previews: PreviewProvider { struct SignInView_Previews: PreviewProvider {
@@ -114,15 +73,3 @@ struct SignInView_Previews: PreviewProvider {
SignInView().environmentObject(AuthSessionStore()) 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
}
}
@@ -21,7 +21,6 @@ struct HeaderView: View {
.font(Font.system(.largeTitle)) .font(Font.system(.largeTitle))
.padding() .padding()
.foregroundColor(NirvanaColor.teal) .foregroundColor(NirvanaColor.teal)
} }
Spacer() Spacer()
@@ -45,7 +44,6 @@ struct HeaderView: View {
.padding() .padding()
.foregroundColor(NirvanaColor.teal) .foregroundColor(NirvanaColor.teal)
} }
} }
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
} }
+26 -26
View File
@@ -8,37 +8,37 @@
import SwiftUI import SwiftUI
struct WelcomeView: View { struct WelcomeView: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var body: some View { 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( 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) { VStack(alignment: .center) {
NavigationLink(destination: SignInView()) { NavigationLink(destination: SignInView()) {
Text("Start Your Detox") 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() .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 //learn more button to usenirvana.com
} }
.padding(.top, 20) .padding(.top, 20)
) )
) )
.navigationBarHidden(true)
} // navigation view
} // View body } // View body
} // View } // View
+9 -12
View File
@@ -13,22 +13,19 @@ import GoogleSignIn
struct nirvana_iosApp: App { struct nirvana_iosApp: App {
@StateObject var authSessionStore: AuthSessionStore = AuthSessionStore() @StateObject var authSessionStore: AuthSessionStore = AuthSessionStore()
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate init() {
var body: some Scene { self.setupAuth()
}
var body: some Scene {
WindowGroup { WindowGroup {
ContentView().environmentObject(authSessionStore) ContentView().environmentObject(authSessionStore)
} }
} }
} }
extension nirvana_iosApp {
class AppDelegate: NSObject, UIApplicationDelegate { private func setupAuth() {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { FirebaseApp.configure()
FirebaseApp.configure()
return true
}
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
} }
} }