getting things organized
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
89288EC9276756DF00E962C4 /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = 89288EC8276756DF00E962C4 /* FirebaseStorage */; };
|
||||
89288ECB27675B9F00E962C4 /* OnboardingTemplateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */; };
|
||||
89AD5573276DD790001658E0 /* SplashView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5572276DD790001658E0 /* SplashView.swift */; };
|
||||
89AD5575276DE724001658E0 /* PhoneCodeVerificationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */; };
|
||||
89B46E71276893E200B74255 /* AuthSessionStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89B46E70276893E200B74255 /* AuthSessionStore.swift */; };
|
||||
89BCABE2276B3CB0009E9B10 /* NavigationStack in Frameworks */ = {isa = PBXBuildFile; productRef = 89BCABE1276B3CB0009E9B10 /* NavigationStack */; };
|
||||
89BCABE5276B3D58009E9B10 /* InnerCircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89BCABE4276B3D58009E9B10 /* InnerCircleView.swift */; };
|
||||
@@ -73,6 +74,7 @@
|
||||
89288EBF276755DF00E962C4 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
|
||||
89288ECA27675B9F00E962C4 /* OnboardingTemplateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTemplateView.swift; sourceTree = "<group>"; };
|
||||
89AD5572276DD790001658E0 /* SplashView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashView.swift; sourceTree = "<group>"; };
|
||||
89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneCodeVerificationView.swift; sourceTree = "<group>"; };
|
||||
89B46E70276893E200B74255 /* AuthSessionStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthSessionStore.swift; sourceTree = "<group>"; };
|
||||
89BCABE4276B3D58009E9B10 /* InnerCircleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InnerCircleView.swift; sourceTree = "<group>"; };
|
||||
89BCABE6276B3D64009E9B10 /* InnerCircleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InnerCircleViewModel.swift; sourceTree = "<group>"; };
|
||||
@@ -274,6 +276,7 @@
|
||||
children = (
|
||||
89BCABEA276D2A07009E9B10 /* PhoneVerificationView.swift */,
|
||||
89BCABEF276D53C3009E9B10 /* PhoneVerificationViewModel.swift */,
|
||||
89AD5574276DE724001658E0 /* PhoneCodeVerificationView.swift */,
|
||||
);
|
||||
path = PhoneVerification;
|
||||
sourceTree = "<group>";
|
||||
@@ -422,6 +425,7 @@
|
||||
89BDCDEA27697F9C00577829 /* UserMenu.swift in Sources */,
|
||||
89BCABE7276B3D64009E9B10 /* InnerCircleViewModel.swift in Sources */,
|
||||
891A15FF27656F9200B26659 /* HeaderView.swift in Sources */,
|
||||
89AD5575276DE724001658E0 /* PhoneCodeVerificationView.swift in Sources */,
|
||||
892179E42765FEB8001E6C60 /* FooterControlsView.swift in Sources */,
|
||||
891A15FD276566B800B26659 /* constants.swift in Sources */,
|
||||
89BCABE5276B3D58009E9B10 /* InnerCircleView.swift in Sources */,
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// PhoneCodeVerificationView.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/18/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import NavigationStack
|
||||
import Combine
|
||||
import Firebase
|
||||
import FirebaseAuth
|
||||
|
||||
struct PhoneCodeVerificationView: View {
|
||||
@EnvironmentObject private var navigationStack: NavigationStack
|
||||
|
||||
@State var verificationCode = ""
|
||||
|
||||
// Alert settings
|
||||
@State var showToast = false
|
||||
@State var toastText = ""
|
||||
@State var toastSubMessage = ""
|
||||
|
||||
@State var isLoading = false
|
||||
|
||||
@FocusState private var focusedInputField: Bool
|
||||
|
||||
let formatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .decimal
|
||||
return formatter
|
||||
}()
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
Color.clear
|
||||
|
||||
OnboardingTemplateView(hdrText: "Let's get you verified", imgName: "undraw_my_password_d-6-kg", bottomActArea: AnyView(
|
||||
VStack {
|
||||
TextField("Code", text: self.$verificationCode)
|
||||
.padding()
|
||||
.background(.ultraThinMaterial)
|
||||
.clipShape(Capsule())
|
||||
.shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20)
|
||||
.font(.title)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.vertical)
|
||||
.keyboardType(.phonePad)
|
||||
.focused(self.$focusedInputField)
|
||||
|
||||
|
||||
if self.verificationCode.count == 6 {
|
||||
Button {
|
||||
print("started verification process of code")
|
||||
|
||||
//disable focused textfield
|
||||
self.focusedInputField.toggle()
|
||||
|
||||
// show loading screen
|
||||
self.isLoading.toggle()
|
||||
|
||||
|
||||
// TODO: do all of this in view model authstore
|
||||
// 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 credential
|
||||
Auth.auth().signIn(with: credential) { (res, err) in
|
||||
// done with the response here, turn off loading screen
|
||||
self.isLoading.toggle()
|
||||
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
//setting in key storage
|
||||
UserDefaults.standard.set(true, forKey: "authVerificationID")
|
||||
|
||||
//TODO: is the auth listener going to find that this person signed in? idk test it
|
||||
|
||||
// firebase either created a new user or is giving back an existing user's id
|
||||
let userId = res?.user.uid
|
||||
let userPhoneNumber = res?.user.phoneNumber
|
||||
print("user id that was authenticated is: \(userId)")
|
||||
print("user id that was authenticated is: \(userPhoneNumber)")
|
||||
|
||||
|
||||
// then sending to next page
|
||||
self.navigationStack.push(PhoneVerificationView()) // verify code page
|
||||
}
|
||||
|
||||
} label: {
|
||||
Text("Verify")
|
||||
.bold()
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
}
|
||||
} else {
|
||||
Text("Verify")
|
||||
.foregroundColor(Color.white.opacity(0.2))
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(Color.white.opacity(0.2)) // show dull button if didn't enter full phone number
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
.animation(.default)
|
||||
}
|
||||
|
||||
}
|
||||
))
|
||||
|
||||
//back button to home
|
||||
Button {
|
||||
print("going back to last page")
|
||||
|
||||
self.navigationStack.pop() // goes back to welcome screen
|
||||
} label: {
|
||||
Label("Back", systemImage: "chevron.left")
|
||||
.labelStyle(.iconOnly)
|
||||
.foregroundColor(NirvanaColor.teal)
|
||||
.padding()
|
||||
}
|
||||
|
||||
if self.isLoading {
|
||||
SplashView()
|
||||
}
|
||||
}
|
||||
.alert(self.toastText, isPresented: self.$showToast) {
|
||||
|
||||
Button("OK", role: ButtonRole.cancel) { }
|
||||
|
||||
} message: {
|
||||
Text(self.toastSubMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PhoneCodeVerificationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PhoneCodeVerificationView().environmentObject(AuthSessionStore())
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ struct PhoneVerificationView: View {
|
||||
// use this in the next screen to verify with the code provided
|
||||
UserDefaults.standard.set(verificationID, forKey: "authVerificationID")
|
||||
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
self.navigationStack.push(PhoneCodeVerificationView()) // verify code page
|
||||
}
|
||||
} label: {
|
||||
VStack {
|
||||
@@ -165,160 +165,11 @@ struct PhoneVerificationView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
struct PhoneVerificationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PhoneVerificationView().environmentObject(AuthSessionStore())
|
||||
}
|
||||
}
|
||||
|
||||
// another view for user to type in the sms code
|
||||
struct PhoneVerificationCodeView: View {
|
||||
@EnvironmentObject private var navigationStack: NavigationStack
|
||||
|
||||
@State var verificationCode = ""
|
||||
|
||||
// Alert settings
|
||||
@State var showToast = false
|
||||
@State var toastText = ""
|
||||
@State var toastSubMessage = ""
|
||||
|
||||
@State var isLoading = false
|
||||
|
||||
@FocusState private var focusedInputField: Bool
|
||||
|
||||
let formatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .decimal
|
||||
return formatter
|
||||
}()
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
Color.clear
|
||||
|
||||
OnboardingTemplateView(hdrText: "Let's get you verified", imgName: "undraw_my_password_d-6-kg", bottomActArea: AnyView(
|
||||
VStack {
|
||||
TextField("Code", text: self.$verificationCode)
|
||||
.padding()
|
||||
.background(.ultraThinMaterial)
|
||||
.clipShape(Capsule())
|
||||
.shadow(color: Color.black.opacity(0.3), radius: 20, x: 0, y: 20)
|
||||
.font(.title)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.vertical)
|
||||
.keyboardType(.phonePad)
|
||||
.focused(self.$focusedInputField)
|
||||
|
||||
|
||||
if self.verificationCode.count == 6 {
|
||||
Button {
|
||||
print("started verification process of code")
|
||||
|
||||
//disable focused textfield
|
||||
self.focusedInputField.toggle()
|
||||
|
||||
// show loading screen
|
||||
self.isLoading.toggle()
|
||||
|
||||
|
||||
// TODO: do all of this in view model authstore
|
||||
// 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 credential
|
||||
Auth.auth().signIn(with: credential) { (res, err) in
|
||||
// done with the response here, turn off loading screen
|
||||
self.isLoading.toggle()
|
||||
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
//setting in key storage
|
||||
UserDefaults.standard.set(true, forKey: "authVerificationID")
|
||||
|
||||
//TODO: is the auth listener going to find that this person signed in? idk test it
|
||||
|
||||
// firebase either created a new user or is giving back an existing user's id
|
||||
let userId = res?.user.uid
|
||||
let userPhoneNumber = res?.user.phoneNumber
|
||||
print("user id that was authenticated is: \(userId)")
|
||||
print("user id that was authenticated is: \(userPhoneNumber)")
|
||||
|
||||
|
||||
// then sending to next page
|
||||
self.navigationStack.push(PhoneVerificationCodeView()) // verify code page
|
||||
}
|
||||
|
||||
} label: {
|
||||
Text("Verify")
|
||||
.bold()
|
||||
.foregroundColor(NirvanaColor.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
}
|
||||
} else {
|
||||
Text("Verify")
|
||||
.foregroundColor(Color.white.opacity(0.2))
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 20)
|
||||
.background(Color.white.opacity(0.2)) // show dull button if didn't enter full phone number
|
||||
.clipShape(Capsule())
|
||||
.shadow(radius:10)
|
||||
.animation(.default)
|
||||
}
|
||||
|
||||
}
|
||||
))
|
||||
|
||||
//back button to home
|
||||
Button {
|
||||
print("going back to last page")
|
||||
|
||||
self.navigationStack.pop() // goes back to welcome screen
|
||||
} label: {
|
||||
Label("Back", systemImage: "chevron.left")
|
||||
.labelStyle(.iconOnly)
|
||||
.foregroundColor(NirvanaColor.teal)
|
||||
.padding()
|
||||
}
|
||||
|
||||
if self.isLoading {
|
||||
SplashView()
|
||||
}
|
||||
}
|
||||
.alert(self.toastText, isPresented: self.$showToast) {
|
||||
|
||||
Button("OK", role: ButtonRole.cancel) { }
|
||||
|
||||
} message: {
|
||||
Text(self.toastSubMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PhoneVerificationCodeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PhoneVerificationCodeView().environmentObject(AuthSessionStore())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ struct SplashView: View {
|
||||
|
||||
struct SplashView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SplashView()
|
||||
SplashView().environmentObject(AuthSessionStore())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user