diff --git a/Splito/UI/Login/EmailLogin/EmailLoginView.swift b/Splito/UI/Login/EmailLogin/EmailLoginView.swift index e237f4f7e..744ce9489 100644 --- a/Splito/UI/Login/EmailLogin/EmailLoginView.swift +++ b/Splito/UI/Login/EmailLogin/EmailLoginView.swift @@ -9,31 +9,31 @@ import SwiftUI import BaseStyle struct EmailLoginView: View { - + @StateObject var viewModel: EmailLoginViewModel - + @FocusState private var focusedField: EmailLoginViewModel.EmailLoginField? - + var body: some View { GeometryReader { proxy in VStack(alignment: .leading, spacing: 0) { ScrollView { VStack(alignment: .leading, spacing: 0) { AppLogoView(geometry: .constant(proxy)) - + Group { EmailFieldView(email: $viewModel.email, focusedField: $focusedField) - + PasswordFieldView(password: $viewModel.password, focusedField: $focusedField, isPasswordVisible: viewModel.isPasswordVisible, handlePasswordEyeTap: viewModel.handlePasswordEyeTap, onEditingChanged: viewModel.onEditingChanged(abc:)) - + Spacer() - + PrimaryButton(text: "Sign in", isEnabled: !viewModel.email.isEmpty && !viewModel.password.isEmpty, showLoader: viewModel.showLoader, onClick: viewModel.onEmailLoginClick) - + Button("Forgot your password?") {} .padding() .underline() @@ -58,15 +58,15 @@ struct EmailLoginView: View { } private struct EmailFieldView: View { - + @Binding var email: String var focusedField: FocusState.Binding - + var body: some View { Text("Email address") .font(.subTitle1()) .foregroundStyle(secondaryText) - + TextField("Your email address", text: $email) .autocapitalization(.none) .keyboardType(.emailAddress) @@ -85,19 +85,19 @@ private struct EmailFieldView: View { } private struct PasswordFieldView: View { - + @Binding var password: String var focusedField: FocusState.Binding - + let isPasswordVisible: Bool var handlePasswordEyeTap: () -> Void var onEditingChanged: (Bool) -> Void - + var body: some View { Text("Password") .font(.subTitle1()) .foregroundStyle(secondaryText) - + HStack { if isPasswordVisible { TextField("Your password", text: $password, onEditingChanged: onEditingChanged) diff --git a/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift b/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift index a911e86e0..56e7b1e67 100644 --- a/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift +++ b/Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift @@ -25,14 +25,14 @@ public class EmailLoginViewModel: BaseViewModel, ObservableObject { self.router = router } - func onEmailSignUp(email: String, password: String) { + func onEmailSignUp() { FirebaseAuth.Auth.auth().createUser(withEmail: email, password: password) { [weak self] authResult, error in guard let self = self else { return } - if let error = error { - LogE("Error during sign up: \(error.localizedDescription)") - self.alert = .init(message: "Sign-up failed: \(error.localizedDescription)") + if let error { + LogE("EmailLoginViewModel: Error during sign up: \(error)") + self.alert = .init(message: "Sign-up failed: \(error)") self.showAlert = true - } else if let authResult = authResult { + } else if let authResult { let user = AppUser(id: authResult.user.uid, firstName: "", lastName: "", emailId: email, phoneNumber: nil, loginType: .Email) Task { @@ -45,12 +45,12 @@ public class EmailLoginViewModel: BaseViewModel, ObservableObject { func onEmailLoginClick() { FirebaseAuth.Auth.auth().signIn(withEmail: email, password: password) { [weak self] _, error in guard let self = self else { return } - if let error = error { - LogE("Error during login: \(error.localizedDescription)") - self.alert = .init(message: "Login failed: \(error.localizedDescription)") + if let error { + LogE("EmailLoginViewModel: Error during login: \(error)") + self.alert = .init(message: "Login failed: \(error)") self.showAlert = true } else { - LogD("User logged in successfully.") + LogD("EmailLoginViewModel: User logged in successfully.") self.onLoginSuccess() } } @@ -62,9 +62,9 @@ public class EmailLoginViewModel: BaseViewModel, ObservableObject { self.preference.isVerifiedUser = true self.preference.user = user self.onLoginSuccess() - LogD("VerifyOtpViewModel: \(#function) User stored successfully.") + LogD("EmailLoginViewModel: \(#function) User stored successfully.") } catch { - LogE("VerifyOtpViewModel: \(#function) Failed to store user: \(error).") + LogE("EmailLoginViewModel: \(#function) Failed to store user: \(error).") self.alert = .init(message: error.localizedDescription) self.showAlert = true }