routing working i think? good enough getting things in place
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Firebase
|
||||||
import FirebaseFirestoreSwift
|
import FirebaseFirestoreSwift
|
||||||
|
|
||||||
struct User: Identifiable, Codable {
|
struct User: Identifiable, Codable {
|
||||||
@@ -18,14 +19,16 @@ struct User: Identifiable, Codable {
|
|||||||
@ServerTimestamp var lastLoggedInTimestamp: Date?
|
@ServerTimestamp var lastLoggedInTimestamp: Date?
|
||||||
@ServerTimestamp var createdTimestamp: Date?
|
@ServerTimestamp var createdTimestamp: Date?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
// careful, if using codingkeys, you have to mapping every attribute thereafter
|
||||||
case nickname
|
// enum CodingKeys: String, CodingKey {
|
||||||
case phoneNumber
|
// case id
|
||||||
case emailAddress
|
// case nickname
|
||||||
case avatar
|
// case phoneNumber
|
||||||
case lastLoggedInTimestamp
|
// case emailAddress
|
||||||
case createdTimestamp
|
// case avatar
|
||||||
}
|
// case lastLoggedInTimestamp
|
||||||
|
// case createdTimestamp
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestUser: Identifiable, Hashable {
|
struct TestUser: Identifiable, Hashable {
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
|
|
||||||
func setupAuthListen() {
|
func setupAuthListen() {
|
||||||
// monitor authentication changes using firebase
|
// 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
|
self.handler = Auth.auth().addStateDidChangeListener { [weak self] res, user in
|
||||||
print("auth listener activated")
|
print("auth listener activated")
|
||||||
|
|
||||||
@@ -135,10 +136,9 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
print("user from firestore in auth listener: \(firestoreUser)")
|
print("user from firestore in auth listener: \(firestoreUser)")
|
||||||
if firestoreUser != nil {
|
if firestoreUser != nil {
|
||||||
self?.user = firestoreUser
|
self?.user = firestoreUser
|
||||||
|
print("lets see if authsessionstore user is being set: \(self?.user)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -30,25 +30,24 @@ struct RouterView: View {
|
|||||||
@EnvironmentObject var navigationStack: NavigationStack
|
@EnvironmentObject var navigationStack: NavigationStack
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SplashView()
|
// authenticated and have user's data
|
||||||
.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
|
if self.authSessionStore.sessionState == SessionState.isAuthenticated {
|
||||||
print("figuring out where to send the user based on state: \(self.authSessionStore.sessionState)")
|
if self.authSessionStore.user != nil {
|
||||||
if self.authSessionStore.sessionState == SessionState.isAuthenticated && updatedUserFromAuth != nil {
|
if self.authSessionStore.user?.nickname == nil && self.authSessionStore.user?.avatar == nil {
|
||||||
print("user stored in authsession store: \(updatedUserFromAuth)")
|
OnboardingTrioView()
|
||||||
// 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())
|
|
||||||
} else {// user is existing user/up and running user -> signs in is pushed nicely right to hub
|
} else {// user is existing user/up and running user -> signs in is pushed nicely right to hub
|
||||||
self.navigationStack.push(InnerCircleView())
|
InnerCircleView()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("sending user to welcome view")
|
OnboardingTrioView()
|
||||||
// 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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user