From eaf74978322801af16d0837826faf02913d7f0be Mon Sep 17 00:00:00 2001 From: dami Date: Tue, 13 Feb 2024 12:41:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C?= =?UTF-8?q?=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=84=9C=EB=B2=84=EC=97=90=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bookmark/KeyChain/KeyChain.swift | 1 + On_off_iOS/On_off_iOS/LogIn/Model/Login.swift | 1 + .../ViewModel/NickNameViewModel.swift | 10 ++- .../ViewModel/ProfileSettingViewModel.swift | 65 ++++++++++--------- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/On_off_iOS/On_off_iOS/Bookmark/KeyChain/KeyChain.swift b/On_off_iOS/On_off_iOS/Bookmark/KeyChain/KeyChain.swift index cbd7e23..588452a 100644 --- a/On_off_iOS/On_off_iOS/Bookmark/KeyChain/KeyChain.swift +++ b/On_off_iOS/On_off_iOS/Bookmark/KeyChain/KeyChain.swift @@ -45,6 +45,7 @@ enum AppleLoginKeyChain: String { /// 프로필 키체인 값 enum ProfileKeyChain: String { + case nickname case fieldOfWork case job case experienceYear diff --git a/On_off_iOS/On_off_iOS/LogIn/Model/Login.swift b/On_off_iOS/On_off_iOS/LogIn/Model/Login.swift index ae8a1f8..3c92ba9 100644 --- a/On_off_iOS/On_off_iOS/LogIn/Model/Login.swift +++ b/On_off_iOS/On_off_iOS/LogIn/Model/Login.swift @@ -26,6 +26,7 @@ struct AppleTokenValidationRequest: Codable { /// 추가 정보 구조체: 프로필: 분야, 직업, 경력 struct AdditionalInfo: Codable { + let nickname: String let fieldOfWork: String let job: String let experienceYear: String diff --git a/On_off_iOS/On_off_iOS/LogIn/NickName/ViewModel/NickNameViewModel.swift b/On_off_iOS/On_off_iOS/LogIn/NickName/ViewModel/NickNameViewModel.swift index a833ed3..d2ea38c 100644 --- a/On_off_iOS/On_off_iOS/LogIn/NickName/ViewModel/NickNameViewModel.swift +++ b/On_off_iOS/On_off_iOS/LogIn/NickName/ViewModel/NickNameViewModel.swift @@ -48,9 +48,13 @@ final class NickNameViewModel { /// 완료버튼 클릭 input.startButtonTapped - .bind(to: output.moveToNext) - .disposed(by: disposeBag) - + .withLatestFrom(input.nickNameTextChanged) + .subscribe(onNext: { nickname in + _ = KeychainWrapper.saveItem(value: nickname, forKey: ProfileKeyChain.nickname.rawValue) + output.moveToNext.onNext(()) + }) + .disposed(by: disposeBag) + return output } diff --git a/On_off_iOS/On_off_iOS/LogIn/ProfileSetting/ViewModel/ProfileSettingViewModel.swift b/On_off_iOS/On_off_iOS/LogIn/ProfileSetting/ViewModel/ProfileSettingViewModel.swift index 28a6315..1a42ef6 100644 --- a/On_off_iOS/On_off_iOS/LogIn/ProfileSetting/ViewModel/ProfileSettingViewModel.swift +++ b/On_off_iOS/On_off_iOS/LogIn/ProfileSetting/ViewModel/ProfileSettingViewModel.swift @@ -77,36 +77,39 @@ final class ProfileSettingViewModel { private func loginWithSelectedData() -> Observable> { guard let loginMethod = KeychainWrapper.loadItem(forKey: LoginMethod.loginMethod.rawValue), - let fieldOfWork = KeychainWrapper.loadItem(forKey: ProfileKeyChain.fieldOfWork.rawValue), - let job = KeychainWrapper.loadItem(forKey: ProfileKeyChain.job.rawValue), - let experienceYear = KeychainWrapper.loadItem(forKey: ProfileKeyChain.experienceYear.rawValue) - else { - return .empty() - } + let nickname = KeychainWrapper.loadItem(forKey: ProfileKeyChain.nickname.rawValue), + let fieldOfWork = KeychainWrapper.loadItem(forKey: ProfileKeyChain.fieldOfWork.rawValue), + let job = KeychainWrapper.loadItem(forKey: ProfileKeyChain.job.rawValue), + let experienceYear = KeychainWrapper.loadItem(forKey: ProfileKeyChain.experienceYear.rawValue) + else { + return .empty() + } /// apple은 최초 이후엔 정보 optional로 nil 값 if loginMethod == "apple" { - let oauthId = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.oauthId.rawValue) ?? "" - let givenName = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.giveName.rawValue) ?? "" - let familyName = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.familyName.rawValue) ?? "" - let email = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.email.rawValue) ?? "" - let identityTokenString = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.identityTokenString.rawValue) ?? "" - let authorizationCodeString = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.authorizationCodeString.rawValue) ?? "" - - let fullName = FullName(giveName: givenName, familyName: familyName) - let additionalInfo = AdditionalInfo(fieldOfWork: fieldOfWork, job: job, experienceYear: experienceYear) - - let request = AppleTokenValidationRequest( - oauthId: oauthId, - fullName: fullName, - email: email, - identityToken: identityTokenString, - authorizationCode: authorizationCodeString, - additionalInfo: additionalInfo - ) - - return loginService.validateAppleTokenAndSendInfo(request: request) - } + let oauthId = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.oauthId.rawValue) ?? "" + let givenName = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.giveName.rawValue) ?? "" + let familyName = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.familyName.rawValue) ?? "" + let email = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.email.rawValue) ?? "" + let identityTokenString = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.identityTokenString.rawValue) ?? "" + let authorizationCodeString = KeychainWrapper.loadItem(forKey: AppleLoginKeyChain.authorizationCodeString.rawValue) ?? "" + + let fullName = FullName(giveName: givenName, familyName: familyName) + + let additionalInfo = AdditionalInfo(nickname: nickname, fieldOfWork: fieldOfWork, job: job, experienceYear: experienceYear) + + let request = AppleTokenValidationRequest( + oauthId: oauthId, + fullName: fullName, + email: email, + identityToken: identityTokenString, + authorizationCode: authorizationCodeString, + additionalInfo: additionalInfo + ) + + return loginService.validateAppleTokenAndSendInfo(request: request) + } + else if loginMethod == "kakao" { guard let identityToken = KeychainWrapper.loadItem(forKey: KakaoLoginKeyChain.idToken.rawValue), let accessToken = KeychainWrapper.loadItem(forKey: KakaoLoginKeyChain.accessToken.rawValue) @@ -114,10 +117,10 @@ final class ProfileSettingViewModel { return .empty() } - let additionalInfo = AdditionalInfo(fieldOfWork: fieldOfWork, job: job, experienceYear: experienceYear) + let additionalInfo = AdditionalInfo(nickname: nickname, fieldOfWork: fieldOfWork, job: job, experienceYear: experienceYear) let request = KakaoTokenValidationRequest(identityToken: identityToken, accessToken: accessToken, additionalInfo: additionalInfo) - return loginService.validateKakaoTokenAndSendInfo(request: request) - } - return .empty() + return loginService.validateKakaoTokenAndSendInfo(request: request) + } + return .empty() } }