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
-5
View File
@@ -11,7 +11,6 @@ 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:
@@ -19,10 +18,6 @@ struct ContentView: View {
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)
} }
@@ -8,10 +8,8 @@
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()) {
@@ -39,6 +37,8 @@ struct WelcomeView: View {
.padding(.top, 20) .padding(.top, 20)
) )
) )
.navigationBarHidden(true)
} // navigation view
} // View body } // View body
} // View } // View
+6 -9
View File
@@ -13,7 +13,10 @@ 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() {
self.setupAuth()
}
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ContentView().environmentObject(authSessionStore) ContentView().environmentObject(authSessionStore)
@@ -21,14 +24,8 @@ struct nirvana_iosApp: App {
} }
} }
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)
} }
} }