trying one method for navigating and on to the next
This commit is contained in:
@@ -9,7 +9,7 @@ import Foundation
|
|||||||
import FirebaseFirestoreSwift
|
import FirebaseFirestoreSwift
|
||||||
|
|
||||||
struct Messages: Identifiable, Codable {
|
struct Messages: Identifiable, Codable {
|
||||||
@DocumentID var id: String? = UUID().uuidString
|
@DocumentID var id: String?
|
||||||
var senderId: String
|
var senderId: String
|
||||||
var receiverId: String
|
var receiverId: String
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Foundation
|
|||||||
import FirebaseFirestoreSwift
|
import FirebaseFirestoreSwift
|
||||||
|
|
||||||
struct User: Identifiable, Codable {
|
struct User: Identifiable, Codable {
|
||||||
@DocumentID var id: String? = UUID().uuidString
|
@DocumentID var id: String?
|
||||||
var nickname: String?
|
var nickname: String?
|
||||||
var phoneNumber: String?
|
var phoneNumber: String?
|
||||||
var emailAddress:String?
|
var emailAddress:String?
|
||||||
|
|||||||
@@ -121,17 +121,22 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
|
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
|
self.sessionState = user == nil ? SessionState.isLoggedOut : SessionState.isAuthenticated
|
||||||
|
|
||||||
// get the user from the auth table in firebase auth
|
// get the user from the auth table in firebase auth
|
||||||
if let user = user {
|
if let uid = user?.uid {
|
||||||
// if we have a user, create a new user model
|
// if we have a user, create a new user model
|
||||||
print("auth listener: Got user: \(user.uid)")
|
print("auth listener: Got user: \(uid)")
|
||||||
print("auth listener: phone number: \(user.phoneNumber!)")
|
print("auth listener: phone number: \(user?.phoneNumber)")
|
||||||
|
|
||||||
// TODO: go to firestore and get full user document for the current authenticated user
|
// get user from firestore and store in environment
|
||||||
// and have this in environment for all pages to access without having to fetch all the time
|
self.firestoreService.getUser(userId: uid) {[weak self] firestoreUser in
|
||||||
|
// if we get a user back, then set this to our authsessionstore for our views
|
||||||
self.getAndSetEnvironmentUserDetails(userId: user.uid)
|
print("user from firestore in auth listener: \(firestoreUser)")
|
||||||
|
if firestoreUser != nil {
|
||||||
|
self?.user = firestoreUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.sessionState = .isAuthenticated
|
self.sessionState = .isAuthenticated
|
||||||
} else {
|
} else {
|
||||||
@@ -141,18 +146,6 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getAndSetEnvironmentUserDetails(userId: String) {
|
|
||||||
self.firestoreService.getUser(userId: userId) {firestoreUser in
|
|
||||||
// if we get a user back, then set this to our instance to allow UI to get published with all user details
|
|
||||||
if firestoreUser != nil {
|
|
||||||
// TODO: prolly useless since we never set up a background thread for the rest of this code before
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.user = firestoreUser
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UIApplication {
|
extension UIApplication {
|
||||||
|
|||||||
@@ -31,21 +31,20 @@ struct RouterView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SplashView()
|
SplashView()
|
||||||
.onAppear() {
|
.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(authSessionStore)
|
print("figuring out where to send the user based on state: \(self.authSessionStore.sessionState)")
|
||||||
print("figuring out where to send the user based on \(self.authSessionStore)")
|
if self.authSessionStore.sessionState == SessionState.isAuthenticated && updatedUserFromAuth != nil {
|
||||||
if authSessionStore.sessionState == SessionState.isAuthenticated {
|
print("user stored in authsession store: \(updatedUserFromAuth)")
|
||||||
if let user = authSessionStore.user {
|
// evaluate where the user should go based on how much data he has
|
||||||
// evaluate where the user should go based on how much data he has
|
|
||||||
|
|
||||||
// user is authenticated but has never picked a username or avatar
|
// user is authenticated but has never picked a username or avatar
|
||||||
if user.nickname != nil && user.avatar != nil {
|
if updatedUserFromAuth?.nickname != nil && updatedUserFromAuth?.avatar != nil {
|
||||||
self.navigationStack.push(OnboardingTrioView())
|
self.navigationStack.push(OnboardingTrioView())
|
||||||
} else {// user is existing user for a year -> 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())
|
self.navigationStack.push(InnerCircleView())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
print("sending user to welcome view")
|
||||||
// go to welcome page at which point they can go and follow the programmatic
|
// go to welcome page at which point they can go and follow the programmatic
|
||||||
// line to the sigin and so on and so forth
|
// line to the sigin and so on and so forth
|
||||||
self.navigationStack.push(WelcomeView())
|
self.navigationStack.push(WelcomeView())
|
||||||
|
|||||||
Reference in New Issue
Block a user