Closed tatsuyamoriguchi closed 1 month ago
Need to learn how to add a code to navigate to another view, Content()?
Register button stops working.
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:
@State
property called showRegistration
, which will control the presentation of the registration modal.isLoggedIn
when the "Register" button is pressed, we toggle the showRegistration
state.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.
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.