Firebase user data storage

I have started the basics of my spelling be app, i have made the user login part and now want to redirect users from my profile view to 5 different quizzes for different languages. However I am not sure how to pass on the user instance to the 5 different quizzes contained in navigation view. In addition, I am not sure how to setup the quizzes so they can ask users questions and then save their responses back to a firebase database.

As for the current setup for my firebase, I currently have one single collection that contains users, their fist name, email, and id.

I have provided the link to my project here:

Any help is much appreciated, thanks.

@Akr1040317

Welcome to the community.

Your AuthViewModel looks to be set up to keep track of your currentUser and I see that you have declared an @EnvironmentObject var viewModel: AuthViewModel at the top of the English quiz so I would have thought that you just do the same in each of the other languages. They would all have access to the same user in the AuthViewModel. Is that what you are getting at?

My english quiz view itself is not working. I am getting the following error whenever i try to navigate to the englishquizview → Thread 1: Fatal error: No ObservableObject of type AuthViewModel found. A View.environmentObject(_:slight_smile: for AuthViewModel may be missing as an ancestor of this view.

Do you have a dummy email and password I can use to test the App?

Don’t worry I created a dummy one.

@Akr1040317

Hmmmm, I think the issue is that you need to have your ProfileView List{ } view code embedded in a NavigationStack { } like this:

struct ProfileView: View {
    @EnvironmentObject var viewModel: AuthViewModel
    
    var body: some View {
        if let user = viewModel.currentUser {
            NavigationStack {
                List {
                    Section {
                        HStack {
                            Text(user.initials)
                                .font(.title)
                                .fontWeight(.semibold)
                                .foregroundColor(Color("Col1"))
                                .frame(width: 72, height: 72)
                                .background(Color(.systemGray3))
                                .clipShape(Circle())

                            VStack(alignment: .leading, spacing: 4) {
                                Text(user.fullname)
                                    .fontWeight(.semibold)
                                    .padding(.top, 4)

                                Text(user.email)
                                    .font(.footnote)
                                    .foregroundColor(.gray)
                            }
                        }
                    }


                    Section("General"){
                        HStack {
                            SettingsRowView(imageName: "gear", title: "Version", tintColor: Color(.systemGray))
                            Spacer()

                            Text("1.0.0")
                                .font(.subheadline)
                                .foregroundColor(.gray)
                        }
                    }

                    Section("Account"){
                        Button{
                            viewModel.signOut()
                        } label: {
                            SettingsRowView(imageName: "arrow.left.circle.fill", title: "Sign Out", tintColor: .red)
                        }

                        Button{
                            print("Delete account..")
                        } label: {
                            SettingsRowView(imageName: "xmark.circle.fill", title: "Delete Account", tintColor: .red)
                        }
                    }

                    Section("Quizzes") {
                        NavigationLink(destination: EnglishQuizView()) {
                            SettingsRowView(imageName: "questionmark.circle.fill", title: "English Quiz", tintColor: .blue)
                        }

                        NavigationLink(destination: SpanishQuizView()) {
                            SettingsRowView(imageName: "questionmark.circle.fill", title: "Spanish Quiz", tintColor: .green)
                        }

                        NavigationLink(destination: FrenchQuizView()) {
                            SettingsRowView(imageName: "questionmark.circle.fill", title: "French Quiz", tintColor: .purple)
                        }

                        NavigationLink(destination: GermanQuizView()) {
                            SettingsRowView(imageName: "questionmark.circle.fill", title: "German Quiz", tintColor: .orange)
                        }

                        NavigationLink(destination: ItalianQuizView()) {
                            SettingsRowView(imageName: "questionmark.circle.fill", title: "Italian Quiz", tintColor: .red)
                        }
                    }

                    // Rest of your sections and content...

                }
            }
        }
    }
}

At least when navigating to the EnglishQuizView it no longer gets angry.