working auth handler and listener and successfuly changing auth and all

This commit is contained in:
talksik
2021-12-14 14:56:58 -08:00
parent 60723a5118
commit d8070b30f3
2 changed files with 16 additions and 7 deletions
+6 -1
View File
@@ -39,6 +39,8 @@ final class AuthSessionStore: ObservableObject, SessionStore {
let clientID = FirebaseApp.app()?.options.clientID let clientID = FirebaseApp.app()?.options.clientID
self.GIDconfig = GIDConfiguration(clientID: clientID!) self.GIDconfig = GIDConfiguration(clientID: clientID!)
print(clientID)
self.setupAuthListen() self.setupAuthListen()
} }
@@ -113,12 +115,15 @@ final class AuthSessionStore: ObservableObject, SessionStore {
if let user = user { if let user = user {
// if we have a user, create a new user model // if we have a user, create a new user model
print("Got user: \(user)") print("Got user: \(user.displayName!)")
self.user = User( self.user = User(
_uid: user.uid, _email: user.email, _displayName: user.displayName, _profilePic: user.photoURL, _phoneNumber: user.phoneNumber) _uid: user.uid, _email: user.email, _displayName: user.displayName, _profilePic: user.photoURL, _phoneNumber: user.phoneNumber)
self.sessionState = .isAuthenticated
} else { } else {
// if we don't have a user, set our session to nil // if we don't have a user, set our session to nil
self.user = nil self.user = nil
self.sessionState = .isLoggedOut
} }
} }
} }
+10 -6
View File
@@ -13,9 +13,8 @@ import GoogleSignIn
struct nirvana_iosApp: App { struct nirvana_iosApp: App {
@StateObject var authSessionStore: AuthSessionStore = AuthSessionStore() @StateObject var authSessionStore: AuthSessionStore = AuthSessionStore()
init() { @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
self.setupAuth()
}
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
@@ -24,8 +23,13 @@ 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)
} }
} }