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 45 additions and 108 deletions
+7 -12
View File
@@ -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()
}
}
}
}
+1 -54
View File
@@ -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
}
}
@@ -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)
}
+26 -26
View File
@@ -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
+11 -14
View File
@@ -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()
}
}