tatsuyamoriguchi / Sleep-Tracer

1 stars 0 forks source link

Add User Login view and functions. #27

Closed tatsuyamoriguchi closed 1 month ago

tatsuyamoriguchi commented 2 months ago

Users input their registered email address and password. Upon submission, the app verifies the credentials against the stored user data. If the credentials are valid, the user is authenticated and granted access to the app.

tatsuyamoriguchi commented 1 month ago

Need to learn how to add a code to navigate to another view, Content()?

tatsuyamoriguchi commented 1 month ago

How to go to another view with button click

tatsuyamoriguchi commented 1 month ago

Register button stops working.

tatsuyamoriguchi commented 1 month ago

How do I reset the keychain in simulator?

tatsuyamoriguchi commented 1 month ago

The issue you're encountering might be due to the way you're toggling the isLoggedIn state. Let's try to address it.

In your code, you're setting isLoggedIn to false when the "Register" button is pressed, which should trigger the display of the registration modal. However, it seems there might be a conflict because isLoggedIn is also used to determine whether the user is logged in or not. This could be causing SwiftUI to behave unexpectedly.

Here's a suggested modification to resolve this:

@State private var showRegistration = false

var body: some View {
    VStack {
        if isLoggedIn {
            ContentView()
        } else {
            // Your login UI
            Button("Register") {
                // Set the state to show registration
                showRegistration.toggle()
            }
            .sheet(isPresented: $showRegistration) {
                // Show Registration modal
                Registration()
            }
        }
    }
}

In this modification:

  1. I introduced a new @State property called showRegistration, which will control the presentation of the registration modal.
  2. Instead of directly modifying isLoggedIn when the "Register" button is pressed, we toggle the showRegistration state.
  3. The registration modal is presented conditionally based on the showRegistration state.

This separation of concerns should help avoid any conflicts and ensure that the registration modal is presented when the "Register" button is pressed.