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
|
// Alert settings
|
||||||
@State var showToast = false
|
@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
|
// TODO: format the input so that it shows the parentheses and stuff (949)923-0445
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -62,25 +63,31 @@ struct PhoneVerificationView: View {
|
|||||||
.padding(.vertical, 20)
|
.padding(.vertical, 20)
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
print("send sms")
|
|
||||||
|
|
||||||
let concatPhoneNumber = "+"+self.ccode+self.phoneNumber
|
let concatPhoneNumber = "+"+self.ccode+self.phoneNumber
|
||||||
// do auth stuff from firebase
|
|
||||||
|
|
||||||
|
// do auth stuff from firebase
|
||||||
PhoneAuthProvider.provider()
|
PhoneAuthProvider.provider()
|
||||||
.verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in
|
.verifyPhoneNumber(concatPhoneNumber, uiDelegate: nil) { verificationID, error in
|
||||||
// problem verifying number showing alert...maybe fake number or something from user
|
// problem verifying number showing alert...maybe fake number or something from user
|
||||||
if error != nil {
|
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()
|
self.showToast.toggle()
|
||||||
|
|
||||||
|
print((error?.localizedDescription)!)
|
||||||
|
|
||||||
return
|
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")
|
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
|
||||||
|
|
||||||
// then async send to next page
|
// 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
|
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
@@ -97,7 +104,7 @@ struct PhoneVerificationView: View {
|
|||||||
|
|
||||||
Text("You might receive an SMS message for verification and standard rates apply.")
|
Text("You might receive an SMS message for verification and standard rates apply.")
|
||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
.foregroundColor(Color.black.opacity(0.7))
|
.foregroundColor(Color.gray)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,11 +122,12 @@ struct PhoneVerificationView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(isPresented: self.$showToast) {
|
.alert(self.toastText, isPresented: self.$showToast) {
|
||||||
Alert(
|
|
||||||
title: Text(self.toastText),
|
Button("OK", role: ButtonRole.cancel) { }
|
||||||
dismissButton: .default(Text("Got it!"))
|
|
||||||
)
|
} message: {
|
||||||
|
Text(self.toastSubMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +146,8 @@ struct PhoneVerificationCodeView: View {
|
|||||||
|
|
||||||
// Alert settings
|
// Alert settings
|
||||||
@State var showToast = false
|
@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 {
|
var body: some View {
|
||||||
ZStack(alignment: .topLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
@@ -181,11 +190,14 @@ struct PhoneVerificationCodeView: View {
|
|||||||
verificationCode: self.verificationCode
|
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
|
Auth.auth().signIn(with: credential) { (res, err) in
|
||||||
if err != nil {
|
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()
|
self.showToast.toggle()
|
||||||
|
|
||||||
|
print((err?.localizedDescription)!)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,11 +241,12 @@ struct PhoneVerificationCodeView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(isPresented: self.$showToast) {
|
.alert(self.toastText, isPresented: self.$showToast) {
|
||||||
Alert(
|
|
||||||
title: Text(self.toastText),
|
Button("OK", role: ButtonRole.cancel) { }
|
||||||
dismissButton: .default(Text("Got it!"))
|
|
||||||
)
|
} message: {
|
||||||
|
Text(self.toastSubMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,21 +28,29 @@ struct nirvana_iosApp: App {
|
|||||||
|
|
||||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||||
FirebaseApp.configure()
|
print("Colors application is starting up. ApplicationDelegate didFinishLaunchingWithOptions.")
|
||||||
return true
|
|
||||||
|
print("initialized Firebase")
|
||||||
|
FirebaseApp.configure()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
||||||
print("\(#function)")
|
print("\(#function)")
|
||||||
Auth.auth().setAPNSToken(deviceToken, type: .sandbox)
|
//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) {
|
func application(_ application: UIApplication, didReceiveRemoteNotification notification: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||||
|
print("did receive remote notification")
|
||||||
print("\(#function)")
|
print("\(#function)")
|
||||||
if Auth.auth().canHandleNotification(notification) {
|
//MARK: add this when I have APN setup through app
|
||||||
completionHandler(.noData)
|
// if Auth.auth().canHandleNotification(notification) {
|
||||||
return
|
// completionHandler(.noData)
|
||||||
}
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For iOS 9+
|
// For iOS 9+
|
||||||
@@ -50,7 +58,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
|||||||
// MARK: turned off google sign in link in for phone below
|
// MARK: turned off google sign in link in for phone below
|
||||||
// return GIDSignIn.sharedInstance.handle(url)
|
// 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) {
|
if Auth.auth().canHandle(url) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user