Skip to content

Commit

Permalink
Remove unwanted code
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-nirali-s committed Dec 16, 2024
1 parent 2e6df97 commit 3a2522a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
28 changes: 1 addition & 27 deletions Data/Data/Store/UserStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import FirebaseFirestore
import FirebaseAuth

class UserStore: ObservableObject {

Expand Down Expand Up @@ -48,7 +47,7 @@ class UserStore: ObservableObject {

func fetchUserBy(email: String) async throws -> AppUser? {
let snapshot = try await usersCollection.whereField("email_id", isEqualTo: email).getDocuments()

if let document = snapshot.documents.first {
let fetchedUser = try document.data(as: AppUser.self)
LogD("UserStore: \(#function) User fetched successfully by email.")
Expand Down Expand Up @@ -88,29 +87,4 @@ class UserStore: ObservableObject {
func deactivateUserAfterDelete(userId: String) async throws {
try await usersCollection.document(userId).updateData(["is_active": false])
}

func deleteAccount() {
// Get the currently signed-in user
guard let user = Auth.auth().currentUser else {
print("No user is currently signed in.")
return
}

// Delete the user's account
user.delete { error in
if let error {
// Handle error (e.g., user may need to reauthenticate)
print("Error deleting account: \(error.localizedDescription)")

// Example: Reauthentication may be required
if let authError = error as? NSError,
authError.code == AuthErrorCode.requiresRecentLogin.rawValue {
print("User needs to reauthenticate before deleting their account.")
// Call a reauthentication flow here
}
} else {
print("User account deleted successfully.")
}
}
}
}
6 changes: 3 additions & 3 deletions Splito/UI/Login/EmailLogin/EmailLoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public class EmailLoginViewModel: BaseViewModel, ObservableObject {

func onLoginClick() {
guard validateEmailAndPassword() else { return }

Task {
do {
isLoginInProgress = true

if let user = try await userRepository.fetchUserBy(email: email) {
if user.loginType != .Email {
isLoginInProgress = false
showAlertFor(title: "Error", message: "This account already exists with a different login method.")
return
}

FirebaseAuth.Auth.auth().signIn(withEmail: email, password: password) { [weak self] result, error in
self?.isLoginInProgress = false
self?.handleAuthResponse(result: result, error: error, isLogin: true)
Expand Down

0 comments on commit 3a2522a

Please sign in to comment.