diff --git a/nirvana-ios/Models/User.swift b/nirvana-ios/Models/User.swift index 92f45a9..be2dbf6 100644 --- a/nirvana-ios/Models/User.swift +++ b/nirvana-ios/Models/User.swift @@ -6,6 +6,7 @@ // import Foundation +import Firebase import FirebaseFirestoreSwift struct User: Identifiable, Codable { @@ -18,14 +19,16 @@ struct User: Identifiable, Codable { @ServerTimestamp var lastLoggedInTimestamp: Date? @ServerTimestamp var createdTimestamp: Date? - enum CodingKeys: String, CodingKey { - case nickname - case phoneNumber - case emailAddress - case avatar - case lastLoggedInTimestamp - case createdTimestamp - } + // careful, if using codingkeys, you have to mapping every attribute thereafter +// enum CodingKeys: String, CodingKey { +// case id +// case nickname +// case phoneNumber +// case emailAddress +// case avatar +// case lastLoggedInTimestamp +// case createdTimestamp +// } } struct TestUser: Identifiable, Hashable { diff --git a/nirvana-ios/Services/AuthSessionStore.swift b/nirvana-ios/Services/AuthSessionStore.swift index ee7a99a..749377a 100644 --- a/nirvana-ios/Services/AuthSessionStore.swift +++ b/nirvana-ios/Services/AuthSessionStore.swift @@ -116,6 +116,7 @@ final class AuthSessionStore: ObservableObject, SessionStore { func setupAuthListen() { // monitor authentication changes using firebase + print("let's see what user looks like in authsession at at the start: \(self.user)") self.handler = Auth.auth().addStateDidChangeListener { [weak self] res, user in print("auth listener activated") @@ -135,10 +136,9 @@ final class AuthSessionStore: ObservableObject, SessionStore { print("user from firestore in auth listener: \(firestoreUser)") if firestoreUser != nil { self?.user = firestoreUser + print("lets see if authsessionstore user is being set: \(self?.user)") } } - - self.sessionState = .isAuthenticated } else { // if we don't have a user, set our session to nil self.user = nil diff --git a/nirvana-ios/Views/Router/RouterView.swift b/nirvana-ios/Views/Router/RouterView.swift index 590c93d..0ec6a25 100644 --- a/nirvana-ios/Views/Router/RouterView.swift +++ b/nirvana-ios/Views/Router/RouterView.swift @@ -30,25 +30,24 @@ struct RouterView: View { @EnvironmentObject var navigationStack: NavigationStack var body: some View { - SplashView() - .onReceive(self.authSessionStore.$user) {updatedUserFromAuth in // observing user because takes longer to get the user details than see updates to sessionstate and we need the user for the logic below - print("figuring out where to send the user based on state: \(self.authSessionStore.sessionState)") - if self.authSessionStore.sessionState == SessionState.isAuthenticated && updatedUserFromAuth != nil { - print("user stored in authsession store: \(updatedUserFromAuth)") - // evaluate where the user should go based on how much data he has - - // user is authenticated but has never picked a username or avatar - if updatedUserFromAuth?.nickname != nil && updatedUserFromAuth?.avatar != nil { - self.navigationStack.push(OnboardingTrioView()) + // authenticated and have user's data + if self.authSessionStore.sessionState == SessionState.isAuthenticated { + if self.authSessionStore.user != nil { + if self.authSessionStore.user?.nickname == nil && self.authSessionStore.user?.avatar == nil { + OnboardingTrioView() } else {// user is existing user/up and running user -> signs in is pushed nicely right to hub - self.navigationStack.push(InnerCircleView()) + InnerCircleView() } } else { - print("sending user to welcome view") - // go to welcome page at which point they can go and follow the programmatic - // line to the sigin and so on and so forth - self.navigationStack.push(WelcomeView()) + OnboardingTrioView() } + + } else if self.authSessionStore.sessionState == SessionState.isLoggedOut { + // go to welcome page at which point they can go and follow the programmatic + // line to the sigin and so on and so forth + WelcomeView() + } else { + SplashView() } } }