removing some stuff regarding apn's and such and slowly improving smoothness of the phone auth as it's still long time
This commit is contained in:
@@ -19,7 +19,8 @@ struct PhoneVerificationView: View {
|
||||
|
||||
// Alert settings
|
||||
@State var showToast = false
|
||||
@State var toastText = "🇺🇸 Only U.S. supported, more countries coming soon!"
|
||||
@State var toastText = ""
|
||||
@State var toastSubMessage = ""
|
||||
|
||||
// TODO: format the input so that it shows the parentheses and stuff (949)923-0445
|
||||
var body: some View {
|
||||
@@ -62,25 +63,31 @@ struct PhoneVerificationView: View {
|
||||
.padding(.vertical, 20)
|
||||
|
||||
Button {
|
||||
print("send sms")
|
||||
|
||||
let concatPhoneNumber = "+"+self.ccode+self.phoneNumber
|
||||
// do auth stuff from firebase
|
||||
|
||||
// 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.toastText = "⚠️ Please try again."
|
||||
self.toastSubMessage = "There was an issue validating your phone number"
|
||||
self.showToast.toggle()
|
||||
|
||||
print((error?.localizedDescription)!)
|
||||
|
||||
return
|
||||
}
|
||||
// Sign in using the verificationID and the code sent to the user
|
||||
// ...
|
||||
|
||||
print("sending sms")
|
||||
|
||||
// TODO: Sign in using the verificationID and the code sent to the user
|
||||
// if there is no user with the phone number, then create one
|
||||
|
||||
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
|
||||
|
||||
// then async send to next page
|
||||
// TODO: coming back after function end and then having 1 second before hitting this...need to use async and combine and all of that to make sure that the main thread is not affected and it's all smooth
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
}
|
||||
} label: {
|
||||
@@ -97,7 +104,7 @@ struct PhoneVerificationView: View {
|
||||
|
||||
Text("You might receive an SMS message for verification and standard rates apply.")
|
||||
.font(.footnote)
|
||||
.foregroundColor(Color.black.opacity(0.7))
|
||||
.foregroundColor(Color.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,11 +122,12 @@ struct PhoneVerificationView: View {
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.alert(isPresented: self.$showToast) {
|
||||
Alert(
|
||||
title: Text(self.toastText),
|
||||
dismissButton: .default(Text("Got it!"))
|
||||
)
|
||||
.alert(self.toastText, isPresented: self.$showToast) {
|
||||
|
||||
Button("OK", role: ButtonRole.cancel) { }
|
||||
|
||||
} message: {
|
||||
Text(self.toastSubMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +146,8 @@ struct PhoneVerificationCodeView: View {
|
||||
|
||||
// Alert settings
|
||||
@State var showToast = false
|
||||
@State var toastText = "There was an error in verifying your account"
|
||||
@State var toastText = ""
|
||||
@State var toastSubMessage = ""
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
@@ -181,11 +190,14 @@ struct PhoneVerificationCodeView: View {
|
||||
verificationCode: self.verificationCode
|
||||
)
|
||||
|
||||
// firebase will now verify the put together credential
|
||||
// firebase will now verify the credential
|
||||
Auth.auth().signIn(with: credential) { (res, err) in
|
||||
if err != nil {
|
||||
self.toastText = (err?.localizedDescription)!
|
||||
self.toastText = "⚠️ Error with Verification"
|
||||
self.toastSubMessage = "Code is invalid. Please try again or re-enter your phone number in the previous page."
|
||||
self.showToast.toggle()
|
||||
|
||||
print((err?.localizedDescription)!)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -229,11 +241,12 @@ struct PhoneVerificationCodeView: View {
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
.alert(isPresented: self.$showToast) {
|
||||
Alert(
|
||||
title: Text(self.toastText),
|
||||
dismissButton: .default(Text("Got it!"))
|
||||
)
|
||||
.alert(self.toastText, isPresented: self.$showToast) {
|
||||
|
||||
Button("OK", role: ButtonRole.cancel) { }
|
||||
|
||||
} message: {
|
||||
Text(self.toastSubMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,21 +28,29 @@ struct nirvana_iosApp: App {
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
FirebaseApp.configure()
|
||||
return true
|
||||
print("Colors application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.")
|
||||
|
||||
print("initialized Firebase")
|
||||
FirebaseApp.configure()
|
||||
return true
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
||||
print("\(#function)")
|
||||
Auth.auth().setAPNSToken(deviceToken, type: .sandbox)
|
||||
}
|
||||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
||||
print("\(#function)")
|
||||
//MARK: add this when I have APN setup through app
|
||||
// gets the APN token so that firebase can send notifications to app
|
||||
// Auth.auth().setAPNSToken(deviceToken, type: .sandbox)
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||
print("did receive remote notification")
|
||||
print("\(#function)")
|
||||
if Auth.auth().canHandleNotification(notification) {
|
||||
completionHandler(.noData)
|
||||
return
|
||||
}
|
||||
//MARK: add this when I have APN setup through app
|
||||
// if Auth.auth().canHandleNotification(notification) {
|
||||
// completionHandler(.noData)
|
||||
// return
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// For iOS 9+
|
||||
@@ -50,7 +58,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
// MARK: turned off google sign in link in for phone below
|
||||
// return GIDSignIn.sharedInstance.handle(url)
|
||||
|
||||
// if the user can be handled by google auth, then it will do so
|
||||
// if the url has to do with phone auth, then it will do so
|
||||
if Auth.auth().canHandle(url) {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user