diff --git a/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate b/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate index d8339ec6..e3e99920 100644 Binary files a/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate and b/fit-a-pet-client/fit-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift b/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift index 4a17dab5..4595f937 100644 --- a/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift +++ b/fit-a-pet-client/fit-a-pet-client/Utils/Constants.swift @@ -42,7 +42,6 @@ enum FindIdPwSwitch{ enum OauthInfo{ static var oauthId = "" -// static var phoneNum = "" static var nonce = "" static var provider = "" } diff --git a/fit-a-pet-client/fit-a-pet-client/Utils/PetCareRegistrationManager.swift b/fit-a-pet-client/fit-a-pet-client/Utils/PetCareRegistrationManager.swift index c2128154..9d7ad524 100644 --- a/fit-a-pet-client/fit-a-pet-client/Utils/PetCareRegistrationManager.swift +++ b/fit-a-pet-client/fit-a-pet-client/Utils/PetCareRegistrationManager.swift @@ -1,5 +1,15 @@ struct PetCareRegistrationManager { static var shared = PetCareRegistrationManager() + + var category: (categoryId: Int, categoryName: String)? { + didSet { + if let category = category { + categoryDictionary = ["categoryId": category.categoryId, "categoryName": category.categoryName] + } else { + categoryDictionary = nil + } + } + } var careName: String? { didSet { updateCareDictionary() } @@ -21,16 +31,6 @@ struct PetCareRegistrationManager { private var categoryDictionary: [String: Any]? private var careDictionary: [String: Any]? - var category: (categoryId: Int, categoryName: String)? { - didSet { - if let category = category { - categoryDictionary = ["categoryId": category.categoryId, "categoryName": category.categoryName] - } else { - categoryDictionary = nil - } - } - } - var categoryDictionaryRepresentation: [String: Any]? { return categoryDictionary } diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift index a6934df0..8d28cfa5 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift @@ -172,6 +172,9 @@ extension FirstVC{ @objc func kakaoLoginBtnTapped(_ sender: UIButton){ + let mainVC = TabBarController() + mainVC.modalPresentationStyle = .fullScreen + let nextVC = InputPhoneNumVC() let nonce = CryptoHelpers.randomNonceString() @@ -212,8 +215,16 @@ extension FirstVC{ let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary guard let jsonObject = object else {return} print("respose jsonData: \(jsonObject)") - RegistDivision.oauth = true - self.navigationController?.pushViewController(nextVC, animated: false) + if let userData = jsonObject["data"] as? [String: Any], let userId = userData["userId"] as? Int { + print("User ID: \(userId)") + UserDefaults.standard.set(userId, forKey: "id") + + self.present(mainVC, animated: false, completion: nil) + } else { + + RegistDivision.oauth = true + self.navigationController?.pushViewController(nextVC, animated: false) + } } case .failure(let error): // Handle failure @@ -226,10 +237,11 @@ extension FirstVC{ } } @objc func googleLoginBtnTapped(_ sender: UIButton){ - let nonce = CryptoHelpers.randomNonceString() - print("nonce 값: \(nonce)") - let hashedString = CryptoHelpers.sha256(nonce) - print("hashedString 값: \(hashedString)") + + let mainVC = TabBarController() + mainVC.modalPresentationStyle = .fullScreen + + let nextVC = InputPhoneNumVC() GIDSignIn.sharedInstance.signIn( withPresenting: self) { signInResult, error in @@ -258,11 +270,8 @@ extension FirstVC{ print("idToken: \(idToken)") OauthInfo.provider = "google" - OauthInfo.nonce = hashedString OauthInfo.oauthId = userId! - //KeychainHelper.saveTempToken(tempToken: idToken) - AnonymousAlamofire.shared.oauthLogin(){ result in switch result { @@ -273,7 +282,17 @@ extension FirstVC{ let object = try?JSONSerialization.jsonObject(with: responseData, options: []) as? NSDictionary guard let jsonObject = object else {return} print("respose jsonData: \(jsonObject)") - RegistDivision.oauth = true + + if let userData = jsonObject["data"] as? [String: Any], let userId = userData["userId"] as? Int { + print("User ID: \(userId)") + UserDefaults.standard.set(userId, forKey: "id") + + self.present(mainVC, animated: false, completion: nil) + } else { + + RegistDivision.oauth = true + self.navigationController?.pushViewController(nextVC, animated: false) + } } case .failure(let error): // Handle failure diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift index d164539a..91dc3e3e 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/LoginVC.swift @@ -177,9 +177,7 @@ class LoginVC: UIViewController{ print("userId: \(userId)") UserDefaults.standard.set(userId, forKey: "id") - self?.fetchUserProfileInfo(completion: { - self?.present(mainVC, animated: false, completion: nil) - }) + self?.present(mainVC, animated: false, completion: nil) } } } catch { @@ -192,38 +190,6 @@ class LoginVC: UIViewController{ } } } - - func fetchUserProfileInfo(completion: @escaping () -> Void) { - - AuthorizationAlamofire.shared.userProfileInfo { userProfileResult in - switch userProfileResult { - case .success(let data): - if let responseData = data { - do { - let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:] - - if let dataDict = jsonObject["data"] as? [String: Any], - let memberDict = dataDict["member"] as? [String: Any] { - - for (key, value) in memberDict { - UserDefaults.standard.set(value, forKey: key) - } - - UserDefaults.standard.synchronize() - } - print("Response JSON Data: \(jsonObject)") - } catch { - print("Error parsing user profile JSON: \(error)") - } - } - - case .failure(let profileError): - print("Error fetching user profile info: \(profileError)") - } - - completion() - } - } @objc func changeFindIdVC(_ sender: UIButton){ FindIdPwSwitch.findAuth = "아이디 찾기" diff --git a/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/MainVC.swift b/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/MainVC.swift index 0aead0f3..78cd8dd1 100644 --- a/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/MainVC.swift +++ b/fit-a-pet-client/fit-a-pet-client/ViewControllers/TabBarVC/MainVC.swift @@ -25,21 +25,14 @@ class MainVC: UIViewController { override func viewDidLoad() { super.viewDidLoad() -// self.navigationItem.title = "반려동물 등록하기" - petCollectionView.delegate = self petCollectionView.dataSource = self layoutScrollView.delegate = self initView() - -// if let cookies = HTTPCookieStorage.shared.cookies { -// for cookie in cookies { -// print("Cookie description: \(cookie.description)") -// // You can access other properties of the cookie here -// } -// } + + fetchUserProfileInfo() } private func initView(){ @@ -140,8 +133,37 @@ class MainVC: UIViewController { let nextVC = InputSpeciesVC(title: "반려동물 등록하기") nextVC.hidesBottomBarWhenPushed = true self.navigationController?.pushViewController(nextVC, animated: false) - - + } + + func fetchUserProfileInfo() { + + AuthorizationAlamofire.shared.userProfileInfo { userProfileResult in + switch userProfileResult { + case .success(let data): + if let responseData = data { + do { + let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:] + + if let dataDict = jsonObject["data"] as? [String: Any], + let memberDict = dataDict["member"] as? [String: Any] { + + for (key, value) in memberDict { + UserDefaults.standard.set(value, forKey: key) + } + + UserDefaults.standard.synchronize() + } + print("Response JSON Data: \(jsonObject)") + } catch { + print("Error parsing user profile JSON: \(error)") + } + } + + case .failure(let profileError): + print("Error fetching user profile info: \(profileError)") + } + + } } }