Good day,
before I start, I want to say iam pretty new in SwiftUI. As the title says, I want to change the view after I loggend in with a button click.
So the login is bounded on a condition that login process itself is successful.
But it seems, I have a misconception in my brain about the things works in swiftUI, because if I click on the button, the swiftUI view doesn't change anymore. So the reason is the condition.
Here is the Code and thanks in advance
@State private var email = ""
@State private var password = ""
@State private var isLoggedIn: Bool = false
@StateObject var user = User(usermail: "")
.........
NavigationStack {
ZStack {
BackgroundView()
VStack {
LogoView()
.padding(.bottom, 25)
VStack(spacing: 20){
EmailField(text: $email)
.padding(.horizontal, 32)
PasswordSecureField(text: $password, placeholder: "Password")
.padding(.horizontal, 32)
Text(self.status)
**HStack {
Spacer()
Button(action: { login() }) {
if self.isLoggedIn == true {
NavigationLink(destination: MainMenuView()
.navigationBarHidden(true),
label: {
AuthenticationButtonView(text: "Sign in")
}
).padding()
}
else {
AuthenticationButtonView(text: "Sign in")
}
}**
func login() {
Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
if error != nil {
print(error?.localizedDescription ?? "")
self.status = "Bad Credentials or not registered"
} else {
self.isLoggedIn = true
print("Login sucessfully")
user.usermail = email
}
}
}