Skip to content

Commit

Permalink
FIX: Bugs and code.
Browse files Browse the repository at this point in the history
Signed-off-by: ParsaKargari <[email protected]>
  • Loading branch information
ParsaKargari committed Feb 8, 2024
1 parent 5c45ebf commit 4cd68ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
35 changes: 30 additions & 5 deletions Rethread/Rethread/UserAuthentication/AuthViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AuthViewModel: ObservableObject {
@Published var userSession: FirebaseAuth.User?
@Published var currentUser: User?
@Published var CLIENT_CODE: String = ""
private var verificationId: String?

init(){
self.userSession = Auth.auth().currentUser
Expand All @@ -34,19 +35,19 @@ class AuthViewModel: ObservableObject {
do {
let result = try await Auth.auth().createUser(withEmail: formData.email, password: formData.password)
self.userSession = result.user

let user = User(id: result.user.uid, firstname: formData.firstName, lastname: formData.lastName,
email: formData.email, dateOfBirth: formData.dateOfBirth, gender: formData.gender,
email: formData.email, dateOfBirth: formData.dateOfBirth, gender: formData.gender,
phoneNumber: formData.phoneNumber,postalCode: formData.postalCode, onboardingComplete: false)

let encodedUser = try Firestore.Encoder().encode(user)
try await Firestore.firestore().collection("users").document(user.id).setData(encodedUser)
await fetchUser()
} catch {
print("DEBUG: Error creating user: \(error.localizedDescription)")
}
}

func updateOnboardingComplete() async throws {
do {
let userRef = Firestore.firestore().collection("users").document(userSession!.uid)
Expand Down Expand Up @@ -79,5 +80,29 @@ class AuthViewModel: ObservableObject {
guard let snapshot = try? await Firestore.firestore().collection("users").document(uid).getDocument() else {return}
self.currentUser = try? snapshot.data(as: User.self)
}



// func sendPhoneAuth() async {
// PhoneAuthProvider.provider().verifyPhoneNumber("+16505551111", uiDelegate: nil) { [weak self] verificationID, error in
// guard let verificationID = verificationID, error == nil else {
// print("DEBUG: Error sending phone auth: \(error!.localizedDescription)")
// return
// }
// self?.verificationId = verificationID
// }
// }
// func verifyPhoneAuth(otp: String) async {
// guard let verificationId = self.verificationId else {return}
// let credential = PhoneAuthProvider.provider().credential(withVerificationID: verificationId, verificationCode: otp)
//
// Auth.auth().signIn(with: credential) { (result, error) in
// if let error = error {
// print("DEBUG: Error verifying phone auth: \(error.localizedDescription)")
// return
// }
// self.userSession = result?.user
// }
// }

}

1 change: 1 addition & 0 deletions Rethread/Rethread/Views/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct OnboardingStep {
let maxSelections: Int
}

// MARK: Onboarding Questions
let onboardingSteps = [
OnboardingStep(question: "What is your favorite color?",
options: ["Red", "Green", "Blue", "Purple"],
Expand Down
12 changes: 5 additions & 7 deletions Rethread/Rethread/Views/VerificationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ struct VerificationView: View {
isLoading = true
if isSignIn {
// MARK: SIGN IN OTP

} else {
// MARK: SIGN UP OTP
let otpCode = otpFields.joined()
Task {
do {
try await viewModel.createUser(formData: formData!)
dismiss()
try await viewModel.createUser(formData: formData!)
dismiss()
} catch {
print("DEBUG: Error verifying user: \(error.localizedDescription)")
}
Expand All @@ -80,11 +81,8 @@ struct VerificationView: View {


Button(action: {
if let phoneNumber = formData?.phoneNumber {
Task {
// MARK: REQUEST NEW CODE
}
}
// MARK: REQUEST NEW CODE

}) {
Text("Request new code")
.foregroundColor(Color.primaryColor)
Expand Down

0 comments on commit 4cd68ba

Please sign in to comment.