From d8070b30f35e84a8ed10be161fae984898cf50c2 Mon Sep 17 00:00:00 2001 From: talksik Date: Tue, 14 Dec 2021 14:56:58 -0800 Subject: [PATCH] working auth handler and listener and successfuly changing auth and all --- nirvana-ios/Auth/AuthSessionStore.swift | 7 ++++++- nirvana-ios/nirvana_iosApp.swift | 16 ++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/nirvana-ios/Auth/AuthSessionStore.swift b/nirvana-ios/Auth/AuthSessionStore.swift index 3a3beb1..fe978be 100644 --- a/nirvana-ios/Auth/AuthSessionStore.swift +++ b/nirvana-ios/Auth/AuthSessionStore.swift @@ -39,6 +39,8 @@ final class AuthSessionStore: ObservableObject, SessionStore { let clientID = FirebaseApp.app()?.options.clientID self.GIDconfig = GIDConfiguration(clientID: clientID!) + print(clientID) + self.setupAuthListen() } @@ -113,12 +115,15 @@ final class AuthSessionStore: ObservableObject, SessionStore { if let user = user { // if we have a user, create a new user model - print("Got user: \(user)") + print("Got user: \(user.displayName!)") self.user = User( _uid: user.uid, _email: user.email, _displayName: user.displayName, _profilePic: user.photoURL, _phoneNumber: user.phoneNumber) + + self.sessionState = .isAuthenticated } else { // if we don't have a user, set our session to nil self.user = nil + self.sessionState = .isLoggedOut } } } diff --git a/nirvana-ios/nirvana_iosApp.swift b/nirvana-ios/nirvana_iosApp.swift index 755cf84..03d4ac5 100644 --- a/nirvana-ios/nirvana_iosApp.swift +++ b/nirvana-ios/nirvana_iosApp.swift @@ -13,9 +13,8 @@ import GoogleSignIn struct nirvana_iosApp: App { @StateObject var authSessionStore: AuthSessionStore = AuthSessionStore() - init() { - self.setupAuth() - } + @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate + var body: some Scene { WindowGroup { @@ -24,8 +23,13 @@ struct nirvana_iosApp: App { } } -extension nirvana_iosApp { - private func setupAuth() { - FirebaseApp.configure() +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) } }