at a place where I just have to debug slowly the process
This commit is contained in:
@@ -15,7 +15,7 @@ struct ContentView: View {
|
||||
NavigationStackView {
|
||||
switch self.authSessionStore.sessionState {
|
||||
case SessionState.isAuthenticated:
|
||||
HomeView()
|
||||
InnerCircleView()
|
||||
case SessionState.isLoggedOut:
|
||||
WelcomeView()
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ import NavigationStack
|
||||
import Combine
|
||||
// TODO: maybe this is useless and just do my own toasts and alerts
|
||||
import PopupView
|
||||
import Firebase
|
||||
import FirebaseAuth
|
||||
|
||||
// user can type in a phone number and then receive a text
|
||||
struct PhoneVerificationView: View {
|
||||
@State var phoneNumber = ""
|
||||
@State var ccode = "+1"
|
||||
@State var ccode = "1"
|
||||
@EnvironmentObject private var navigationStack: NavigationStack
|
||||
|
||||
// Alert settings
|
||||
@@ -29,7 +31,7 @@ struct PhoneVerificationView: View {
|
||||
OnboardingTemplateView(hdrText: "Let's get you verified", imgName: "undraw_my_password_d-6-kg", bottomActArea: AnyView(
|
||||
VStack {
|
||||
HStack {
|
||||
Text(ccode)
|
||||
Text("+\(ccode)")
|
||||
.padding()
|
||||
.background(.ultraThinMaterial)
|
||||
.clipShape(Circle())
|
||||
@@ -61,21 +63,43 @@ struct PhoneVerificationView: View {
|
||||
.padding(.vertical, 20)
|
||||
|
||||
Button {
|
||||
print("send verification")
|
||||
|
||||
// do auth stuff
|
||||
// then async send to next page
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
print("send sms")
|
||||
|
||||
let concatPhoneNumber = "+"+self.ccode+self.phoneNumber
|
||||
// do auth stuff from firebase
|
||||
|
||||
PhoneAuthProvider.provider()
|
||||
.verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in
|
||||
// problem verifying number showing alert...maybe fake number or something from user
|
||||
if error != nil {
|
||||
self.toastText = (error?.localizedDescription)!
|
||||
self.showToast.toggle()
|
||||
return
|
||||
}
|
||||
// Sign in using the verificationID and the code sent to the user
|
||||
// ...
|
||||
|
||||
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
|
||||
|
||||
// then async send to next page
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
}
|
||||
} label: {
|
||||
Text("Send Verification")
|
||||
.bold()
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
VStack {
|
||||
Text("Send Verification")
|
||||
.fontWeight(.heavy)
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(self.phoneNumber.count == 10 ? NirvanaColor.teal : Color.white.opacity(0.2)) // show dull button if didn't enter full phone number
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
.animation(.default)
|
||||
|
||||
Text("You might receive an SMS message for verification and standard rates apply.")
|
||||
.font(.footnote)
|
||||
.foregroundColor(Color.black.opacity(0.7))
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
@@ -118,6 +142,10 @@ struct PhoneVerificationCodeView: View {
|
||||
|
||||
@State var verificationCode = ""
|
||||
|
||||
// Alert settings
|
||||
@State var showToast = false
|
||||
@State var toastText = "There was an error in verifying your account"
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
Color.clear
|
||||
@@ -133,21 +161,47 @@ struct PhoneVerificationCodeView: View {
|
||||
.font(.subheadline)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.vertical)
|
||||
// .onReceive(Just(self.$verificationCode)) {newValue in
|
||||
// let filtered = newValue.filter {
|
||||
// "0123456789".contains($0)
|
||||
// }
|
||||
// .onReceive(Just(self.$verificationCode)) { newValue in
|
||||
// let filtered = newValue.filter { "0123456789".contains($0) }
|
||||
//
|
||||
// if filtered != newValue {
|
||||
// self.$verificationCode = filtered
|
||||
// self.verificationCode = filtered
|
||||
// }
|
||||
// }
|
||||
|
||||
Button {
|
||||
print("Verify")
|
||||
print("verify code")
|
||||
|
||||
// do auth stuff
|
||||
|
||||
// get it from the previous screen but from storage
|
||||
let verificationID = UserDefaults.standard.string(forKey: "authVerificationID")
|
||||
|
||||
if verificationID == nil {
|
||||
self.toastText = "There was an error validating your code."
|
||||
self.showToast.toggle()
|
||||
}
|
||||
// if we got a value, then continue with verifying their code
|
||||
let credential = PhoneAuthProvider.provider().credential(
|
||||
withVerificationID: verificationID!,
|
||||
verificationCode: self.verificationCode
|
||||
)
|
||||
|
||||
// firebase will now verify the put together credential
|
||||
Auth.auth().signIn(with: credential) { (res, err) in
|
||||
if err != nil {
|
||||
self.toastText = (err?.localizedDescription)!
|
||||
self.showToast.toggle()
|
||||
return
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(true, forKey: "authVerificationID")
|
||||
|
||||
}
|
||||
|
||||
// then async send to next page
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
|
||||
|
||||
} label: {
|
||||
Text("Send Verification")
|
||||
@@ -174,6 +228,13 @@ struct PhoneVerificationCodeView: View {
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.alert(isPresented: self.$showToast) {
|
||||
Alert(
|
||||
title: Text(self.toastText),
|
||||
message: Text("Go back and try again or re-enter phone number."),
|
||||
dismissButton: .default(Text("Got it!"))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ final class PhoneVerificationViewModel : ObservableObject {
|
||||
}
|
||||
|
||||
extension String {
|
||||
// custom function to give (949)920-0392 and get out the right thing
|
||||
func applyPatternOnNumbers(pattern: String, replacementCharacter: Character) -> String {
|
||||
var pureNumber = self.replacingOccurrences( of: "[^0-9]", with: "", options: .regularExpression)
|
||||
for index in 0 ..< pattern.count {
|
||||
|
||||
Reference in New Issue
Block a user