From 86a50a7f7c6879a3dfaf110d6e60501daf9c596c Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 00:37:29 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[Fix]=20#129=20-=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=9E=AC=EB=B0=9C=EA=B8=89=20API=EC=97=90=EC=84=9C=20401?= =?UTF-8?q?=EC=9D=B4=20=EC=99=94=EC=9D=84=20=EB=95=8C=EB=8A=94=20retry=20?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runnect-iOS/Runnect-iOS/Network/Service/AuthInterceptor.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Service/AuthInterceptor.swift b/Runnect-iOS/Runnect-iOS/Network/Service/AuthInterceptor.swift index 32017703..8470cc98 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Service/AuthInterceptor.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Service/AuthInterceptor.swift @@ -35,7 +35,8 @@ final class AuthInterceptor: RequestInterceptor { func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { print("retry 진입") - guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 + guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401, let pathComponents = request.request?.url?.pathComponents, + !pathComponents.contains("getNewToken") else { completion(.doNotRetryWithError(error)) return From c76d2a83033228e1a389b689549443587e460a7e Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 00:47:33 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[Feat]=20#129=20-=20LogoutVC=EB=A5=BC=20RNA?= =?UTF-8?q?lertVC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=9A=B0?= =?UTF-8?q?=EC=B8=A1=20=EB=B2=84=ED=8A=BC=20=EC=95=A1=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 8 +++---- .../UIComponents/RNAlertVC.swift} | 23 ++++++++++++------- .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 5 +++- 3 files changed, 23 insertions(+), 13 deletions(-) rename Runnect-iOS/Runnect-iOS/{Presentation/MyPage/VC/SettingVC/LogoutVC.swift => Global/UIComponents/RNAlertVC.swift} (83%) diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 7f32d704..267f3dbe 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -21,7 +21,7 @@ A3C2CACE29E313CC00EC525B /* SettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CACD29E313CC00EC525B /* SettingVC.swift */; }; A3C2CAD329E4F77C00EC525B /* TermsOfServiceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */; }; A3C2CAD529E4F85400EC525B /* PersonalInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */; }; - A3C2CAD729E53B2900EC525B /* LogoutVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD629E53B2900EC525B /* LogoutVC.swift */; }; + A3C2CAD729E53B2900EC525B /* RNAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD629E53B2900EC525B /* RNAlertVC.swift */; }; A3C2CADB29E9A12400EC525B /* DeleteAccountVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */; }; A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77829CF03D200DD54EC /* AuthRouter.swift */; }; A3D1A77E29CF09B600DD54EC /* SignInResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */; }; @@ -171,7 +171,7 @@ A3C2CACD29E313CC00EC525B /* SettingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingVC.swift; sourceTree = ""; }; A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsOfServiceVC.swift; sourceTree = ""; }; A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalInfoVC.swift; sourceTree = ""; }; - A3C2CAD629E53B2900EC525B /* LogoutVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutVC.swift; sourceTree = ""; }; + A3C2CAD629E53B2900EC525B /* RNAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNAlertVC.swift; sourceTree = ""; }; A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountVC.swift; sourceTree = ""; }; A3D1A77829CF03D200DD54EC /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInResponseDto.swift; sourceTree = ""; }; @@ -391,7 +391,6 @@ A3C2CACD29E313CC00EC525B /* SettingVC.swift */, A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */, A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */, - A3C2CAD629E53B2900EC525B /* LogoutVC.swift */, A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */, ); path = SettingVC; @@ -1032,6 +1031,7 @@ CE9291262965D0ED0010959C /* StatsInfoView.swift */, CE6B63D729673450003F900F /* ListEmptyView.swift */, CEB0BCBB29D123350048CCD5 /* GuideView.swift */, + A3C2CAD629E53B2900EC525B /* RNAlertVC.swift */, ); path = UIComponents; sourceTree = ""; @@ -1361,7 +1361,7 @@ CE40BB1C2967E4910030ABCA /* RunningWaitingVC.swift in Sources */, CE6B63D6296731F9003F900F /* ScrapCourseListView.swift in Sources */, CE6655F8295D90CF00C64E12 /* adjusted+.swift in Sources */, - A3C2CAD729E53B2900EC525B /* LogoutVC.swift in Sources */, + A3C2CAD729E53B2900EC525B /* RNAlertVC.swift in Sources */, DAD5A3E2296D4C6500C8166B /* PickedMapListResponseDto.swift in Sources */, CE4545CB295D7AF4003201E1 /* SceneDelegate.swift in Sources */, A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/LogoutVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift similarity index 83% rename from Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/LogoutVC.swift rename to Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift index d3644fc2..adcb5578 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/LogoutVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift @@ -10,17 +10,19 @@ import UIKit import SnapKit import Then -final class LogoutVC: UIViewController { +final class RNAlertVC: UIViewController { // MARK: - Properties + var rightButtonTapAction: (() -> Void)? + // MARK: - UI Components private let containerView = UIView().then { $0.layer.cornerRadius = 15 } - private let logoutQuestionLabel = UILabel().then { + private let DescriptionLabel = UILabel().then { $0.text = "로그아웃 하시겠어요?" $0.font = .b4 $0.textColor = .g2 @@ -54,7 +56,7 @@ final class LogoutVC: UIViewController { // MARK: - Methods -extension LogoutVC { +extension RNAlertVC { override func touchesBegan(_ touches: Set, with event: UIEvent?) { super.touchesBegan(touches, with: event) if let touch = touches.first, touch.view == self.view { @@ -64,20 +66,25 @@ extension LogoutVC { private func setAddTarget() { self.noButton.addTarget(self, action: #selector(touchUpNoButton), for: .touchUpInside) + self.yesButton.addTarget(self, action: #selector(touchYesButton), for: .touchUpInside) } } // MARK: - @objc Function -extension LogoutVC { - @objc func touchUpNoButton() { +extension RNAlertVC { + @objc private func touchUpNoButton() { dismiss(animated: false) } + + @objc private func touchYesButton() { + self.rightButtonTapAction?() + } } // MARK: - Layout Helpers -extension LogoutVC { +extension RNAlertVC { private func setUI() { view.backgroundColor = .black.withAlphaComponent(0.8) containerView.backgroundColor = .w1 @@ -93,9 +100,9 @@ extension LogoutVC { make.height.equalTo(126) } - containerView.addSubviews(logoutQuestionLabel, yesButton, noButton) + containerView.addSubviews(DescriptionLabel, yesButton, noButton) - logoutQuestionLabel.snp.makeConstraints { make in + DescriptionLabel.snp.makeConstraints { make in make.centerX.equalToSuperview() make.top.equalToSuperview().offset(26) } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index 8d305225..ff084181 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -97,7 +97,10 @@ extension PersonalInfoVC { } private func pushToLogoutVC() { - let logoutVC = LogoutVC() + let logoutVC = RNAlertVC() + logoutVC.rightButtonTapAction = { + print("로그아웃 버튼 클릭!~~!") + } logoutVC.modalPresentationStyle = .overFullScreen self.present(logoutVC, animated: false) } From 734738223a7187f993872a7600424b0b6b9258a8 Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 00:52:00 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[Feat]=20#129=20-=20RNAlertVC=EC=97=90?= =?UTF-8?q?=EC=84=9C=20description=EC=9D=84=20=EC=B4=88=EA=B8=B0=ED=99=94?= =?UTF-8?q?=20=EC=8B=9C=EC=A0=90=EC=97=90=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/UIComponents/RNAlertVC.swift | 16 ++++++++++++---- .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 11 ++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift b/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift index adcb5578..fe610b6e 100644 --- a/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift +++ b/Runnect-iOS/Runnect-iOS/Global/UIComponents/RNAlertVC.swift @@ -22,8 +22,7 @@ final class RNAlertVC: UIViewController { $0.layer.cornerRadius = 15 } - private let DescriptionLabel = UILabel().then { - $0.text = "로그아웃 하시겠어요?" + private let descriptionLabel = UILabel().then { $0.font = .b4 $0.textColor = .g2 } @@ -44,6 +43,15 @@ final class RNAlertVC: UIViewController { $0.layer.cornerRadius = 10 } + init(description: String) { + super.init(nibName: nil, bundle: nil) + self.descriptionLabel.text = description + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + // MARK: - View Life Cycle override func viewDidLoad() { @@ -100,9 +108,9 @@ extension RNAlertVC { make.height.equalTo(126) } - containerView.addSubviews(DescriptionLabel, yesButton, noButton) + containerView.addSubviews(descriptionLabel, yesButton, noButton) - DescriptionLabel.snp.makeConstraints { make in + descriptionLabel.snp.makeConstraints { make in make.centerX.equalToSuperview() make.top.equalToSuperview().offset(26) } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index ff084181..1f9178b2 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -97,9 +97,9 @@ extension PersonalInfoVC { } private func pushToLogoutVC() { - let logoutVC = RNAlertVC() - logoutVC.rightButtonTapAction = { - print("로그아웃 버튼 클릭!~~!") + let logoutVC = RNAlertVC(description: "로그아웃 하시겠어요?") + logoutVC.rightButtonTapAction = { [weak self] in + self?.logout() } logoutVC.modalPresentationStyle = .overFullScreen self.present(logoutVC, animated: false) @@ -110,6 +110,11 @@ extension PersonalInfoVC { deleteAccountVC.modalPresentationStyle = .overFullScreen self.present(deleteAccountVC, animated: false) } + + private func logout() { + print("로그아웃 버튼 클릭!~~!") + + } } // MARK: - Layout Helpers From 424cfa0a4bde921ecf9dac9a34a472be1e0c9665 Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 01:01:45 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[Feat]=20#129=20-=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/Utils/RNUtils/UserManager.swift | 10 ++++++++++ .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift index 861e77d3..604ce2c2 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/UserManager.swift @@ -90,4 +90,14 @@ final class UserManager { } } } + + func logout() { + self.resetTokens() + } + + private func resetTokens() { + self.accessToken = nil + self.refreshToken = nil + self.isKakao = nil + } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index 1f9178b2..0d2f764f 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -112,8 +112,15 @@ extension PersonalInfoVC { } private func logout() { - print("로그아웃 버튼 클릭!~~!") - + UserManager.shared.logout() + self.showSplashVC() + } + + private func showSplashVC() { + let splashVC = SplashVC() + let navigationController = UINavigationController(rootViewController: splashVC) + guard let window = self.view.window else { return } + ViewControllerUtils.setRootViewController(window: window, viewController: navigationController, withAnimation: true) } } From 0777c9bd1785843de85d96e5c810e90a26236e6e Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 01:16:10 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[Feat]=20#129=20-=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 6 ++- .../Network/Dto/MyPageDto/.gitkeep | 0 .../Dto/MyPageDto/UserDeleteResponseDto.swift | 12 +++++ .../Network/Router/UserRouter.swift | 7 ++- .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 46 ++++++++++++++++++- 5 files changed, 66 insertions(+), 5 deletions(-) delete mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 267f3dbe..ab7a239f 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -145,6 +145,7 @@ CEEC6B492961C5E200D00E1E /* SplashVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B482961C5E200D00E1E /* SplashVC.swift */; }; CEEC6B4B2961D89700D00E1E /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */; }; CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */; }; + CEFA9A2F29FC263700F2D0CF /* UserDeleteResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */; }; DA20D847296697A600F1581F /* MyCourseSelectVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D846296697A600F1581F /* MyCourseSelectVC.swift */; }; DA20D849296697B400F1581F /* CourseUploadVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D848296697B400F1581F /* CourseUploadVC.swift */; }; DA20D84E2966A9B300F1581F /* CourseSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */; }; @@ -186,7 +187,6 @@ CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = ""; }; CE0D9FD229648DA300CEB5CD /* CustomAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertVC.swift; sourceTree = ""; }; CE10063929680C5700FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; - CE10063D29680C8100FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064D29680D2500FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10064F29680D3300FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; CE10065029680D3800FD31FB /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; @@ -308,6 +308,7 @@ CEEC6B482961C5E200D00E1E /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = ""; }; CEEC6B4A2961D89700D00E1E /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; CEF3CD99296DB305002723A1 /* CourseDetailResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailResponseDto.swift; sourceTree = ""; }; + CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDeleteResponseDto.swift; sourceTree = ""; }; DA20D846296697A600F1581F /* MyCourseSelectVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyCourseSelectVC.swift; sourceTree = ""; }; DA20D848296697B400F1581F /* CourseUploadVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseUploadVC.swift; sourceTree = ""; }; DA20D84D2966A9B300F1581F /* CourseSearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseSearchVC.swift; sourceTree = ""; }; @@ -451,10 +452,10 @@ CE10063429680C0800FD31FB /* MyPageDto */ = { isa = PBXGroup; children = ( - CE10063D29680C8100FD31FB /* .gitkeep */, A3F67AE1296D33AC001598A2 /* MyPageDto.swift */, A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */, A3305A96296EF58C000B1A10 /* GoalRewardInfoDto.swift */, + CEFA9A2E29FC263700F2D0CF /* UserDeleteResponseDto.swift */, ); path = MyPageDto; sourceTree = ""; @@ -1375,6 +1376,7 @@ DAD5A3D8296C6D9600C8166B /* AdImageCollectionViewCell.swift in Sources */, CE18E890296C76C100FEB569 /* RNLocationModel.swift in Sources */, CE6655DC295D873500C64E12 /* UIButton+.swift in Sources */, + CEFA9A2F29FC263700F2D0CF /* UserDeleteResponseDto.swift in Sources */, CE21C02C299E601000F62AF5 /* ScrapRouter.swift in Sources */, A3D1A78029CF142E00DD54EC /* UserManager.swift in Sources */, A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift new file mode 100644 index 00000000..54b30f12 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/UserDeleteResponseDto.swift @@ -0,0 +1,12 @@ +// +// UserDeleteResponseDto.swift +// Runnect-iOS +// +// Created by sejin on 2023/04/29. +// + +import Foundation + +struct UserDeleteResponseDto: Codable { + let deletedUserId: Int +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift index b3bcce38..ba8ea315 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift @@ -12,6 +12,7 @@ import Moya enum UserRouter { case getMyPageInfo case updateUserNickname(nickname: String) + case deleteUser } extension UserRouter: TargetType { @@ -25,7 +26,7 @@ extension UserRouter: TargetType { var path: String { switch self { - case .getMyPageInfo, .updateUserNickname: + case .getMyPageInfo, .updateUserNickname, .deleteUser: return "/user" } } @@ -36,12 +37,14 @@ extension UserRouter: TargetType { return .get case .updateUserNickname: return .patch + case .deleteUser: + return .delete } } var task: Moya.Task { switch self { - case .getMyPageInfo: + case .getMyPageInfo, .deleteUser: return .requestPlain case .updateUserNickname(let nickname): return .requestParameters(parameters: ["nickname": nickname], encoding: JSONEncoding.default) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index 0d2f764f..91223e99 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -12,6 +12,10 @@ import Then final class PersonalInfoVC: UIViewController { + // MARK: - Properties + + private let userProvider = Providers.userProvider + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton).setTitle("계정 정보") @@ -106,7 +110,10 @@ extension PersonalInfoVC { } private func pushToDeleteAccountVC() { - let deleteAccountVC = DeleteAccountVC() + let deleteAccountVC = RNAlertVC(description: "정말로 탈퇴하시겠어요?") + deleteAccountVC.rightButtonTapAction = { [weak self] in + self?.deleteUser() + } deleteAccountVC.modalPresentationStyle = .overFullScreen self.present(deleteAccountVC, animated: false) } @@ -116,6 +123,10 @@ extension PersonalInfoVC { self.showSplashVC() } + private func deleteUserDidComplete() { + self.logout() + } + private func showSplashVC() { let splashVC = SplashVC() let navigationController = UINavigationController(rootViewController: splashVC) @@ -222,3 +233,36 @@ extension PersonalInfoVC { } } } + +// MARK: - Network + +extension PersonalInfoVC { + private func deleteUser() { + LoadingIndicator.showLoading() + self.userProvider.request(.deleteUser) { [weak self] result in + LoadingIndicator.hideLoading() + guard let self = self else { return } + switch result { + case .success(let response): + let status = response.statusCode + if 200..<300 ~= status { + do { + let responseDto = try response.map(BaseResponse.self) + guard let data = responseDto.data else { return } + print("삭제된 유저 아이디: \(data.deletedUserId)") + self.deleteUserDidComplete() + } catch { + print(error.localizedDescription) + } + } + if status >= 400 { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error) + self.showNetworkFailureToast() + } + } + } +} From 176615313ab3747762586db7c31432fb0fb510fd Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 01:33:27 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[Chore]=20#129=20-=20=EC=BD=94=EC=8A=A4=20?= =?UTF-8?q?=EB=B0=9C=EA=B2=AC=20=EC=97=85=EB=A1=9C=EB=93=9C=20=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/Literal/ImageLiterals.swift | 3 +- .../ic_plus.imageset/Contents.json | 9 ++---- .../ic_plus.imageset/Group 9553.png | Bin 0 -> 203 bytes .../ic_plus.imageset/Group 9553@2x.png | Bin 0 -> 236 bytes .../ic_plus.imageset/Group 9553@3x.png | Bin 0 -> 348 bytes .../ic_plus_button.imageset/Contents.json | 26 ++++++++++++++++++ .../plus.png | Bin .../plus@2x.png | Bin .../plus@3x.png | Bin .../Views/VC/CourseDiscoveryVC.swift | 15 +++++++--- 10 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553.png create mode 100644 Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@2x.png create mode 100644 Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@3x.png create mode 100644 Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus_button.imageset/Contents.json rename Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/{ic_plus.imageset => ic_plus_button.imageset}/plus.png (100%) rename Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/{ic_plus.imageset => ic_plus_button.imageset}/plus@2x.png (100%) rename Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/{ic_plus.imageset => ic_plus_button.imageset}/plus@3x.png (100%) diff --git a/Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift b/Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift index 849f47c8..c625596e 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Literal/ImageLiterals.swift @@ -31,7 +31,7 @@ enum ImageLiterals { static var icMapStart: UIImage { .load(named: "ic_map_start") } static var icMypageFill: UIImage { .load(named: "ic_mypage_fill") } static var icMypage: UIImage { .load(named: "ic_mypage") } - static var icPlus: UIImage { .load(named: "ic_plus") } + static var icPlusButton: UIImage { .load(named: "ic_plus_button") } static var icSearch: UIImage { .load(named: "ic_search") } static var icStar: UIImage { .load(named: "ic_star") } static var icStar2: UIImage { .load(named: "ic_star2") } @@ -43,6 +43,7 @@ enum ImageLiterals { static var icLocationOverlay: UIImage { .load(named: "ic_location_overlay") } static var icLogoCircle: UIImage { .load(named: "ic_logo_circle") } static var icMore: UIImage { .load(named: "ic_more") } + static var icPlus: UIImage { .load(named: "ic_plus") } // img static var imgBackground: UIImage { .load(named: "img_background") } diff --git a/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Contents.json b/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Contents.json index 044ff80f..9c8472d0 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Contents.json +++ b/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Contents.json @@ -1,17 +1,17 @@ { "images" : [ { - "filename" : "plus.png", + "filename" : "Group 9553.png", "idiom" : "universal", "scale" : "1x" }, { - "filename" : "plus@2x.png", + "filename" : "Group 9553@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "plus@3x.png", + "filename" : "Group 9553@3x.png", "idiom" : "universal", "scale" : "3x" } @@ -19,8 +19,5 @@ "info" : { "author" : "xcode", "version" : 1 - }, - "properties" : { - "template-rendering-intent" : "original" } } diff --git a/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553.png b/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553.png new file mode 100644 index 0000000000000000000000000000000000000000..29e97a231d8b4d9dde02567e1d3606308986ccf4 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^{2``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eBeuAfqV@L(#(@7V38x(k4Ru>AGT?{M`cDw9* zX~JQk!y_pUs_q|b-SeXj#us#$GNRFd(Lif u6U)kfo5RH?a%nP4sPUt@`_CA5>+5CzQ*Go~%&iHui^0>?&t;ucLK6UwJ3=-9 literal 0 HcmV?d00001 diff --git a/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@2x.png b/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..fecd014db5676ccdd8ba581335c2ea8893569336 GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9E$svykh8Km+7D9BhG zTtK#9uEV90}Z$Gyje<&9;s_An~~J@ z_R+Hk`=9Mx@rx2- literal 0 HcmV?d00001 diff --git a/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@3x.png b/Runnect-iOS/Runnect-iOS/Global/Resource/Assets.xcassets/ic_plus.imageset/Group 9553@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..fffad8b5df59331d807ad67b2c737e8209801fc9 GIT binary patch literal 348 zcmeAS@N?(olHy`uVBq!ia0vp^x**KK1|+Sd9?b$$oCO|{#S9FJ79h;%I?XTvD9BhG zA24C{_3Uj z{?+$vttu|*$DiE6)%U}t=g Date: Sat, 29 Apr 2023 01:46:01 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[Del]=20#129=20-=20DeleteAccountVC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 4 - .../MyPage/VC/SettingVC/DeleteAccountVC.swift | 119 ------------------ 2 files changed, 123 deletions(-) delete mode 100644 Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/DeleteAccountVC.swift diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index ab7a239f..ecd3af5e 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -22,7 +22,6 @@ A3C2CAD329E4F77C00EC525B /* TermsOfServiceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */; }; A3C2CAD529E4F85400EC525B /* PersonalInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */; }; A3C2CAD729E53B2900EC525B /* RNAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CAD629E53B2900EC525B /* RNAlertVC.swift */; }; - A3C2CADB29E9A12400EC525B /* DeleteAccountVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */; }; A3D1A77929CF03D200DD54EC /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77829CF03D200DD54EC /* AuthRouter.swift */; }; A3D1A77E29CF09B600DD54EC /* SignInResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */; }; A3D1A78029CF142E00DD54EC /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3D1A77F29CF142E00DD54EC /* UserManager.swift */; }; @@ -173,7 +172,6 @@ A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TermsOfServiceVC.swift; sourceTree = ""; }; A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalInfoVC.swift; sourceTree = ""; }; A3C2CAD629E53B2900EC525B /* RNAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNAlertVC.swift; sourceTree = ""; }; - A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountVC.swift; sourceTree = ""; }; A3D1A77829CF03D200DD54EC /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = ""; }; A3D1A77D29CF09B600DD54EC /* SignInResponseDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInResponseDto.swift; sourceTree = ""; }; A3D1A77F29CF142E00DD54EC /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = ""; }; @@ -392,7 +390,6 @@ A3C2CACD29E313CC00EC525B /* SettingVC.swift */, A3C2CAD229E4F77C00EC525B /* TermsOfServiceVC.swift */, A3C2CAD429E4F85400EC525B /* PersonalInfoVC.swift */, - A3C2CADA29E9A12400EC525B /* DeleteAccountVC.swift */, ); path = SettingVC; sourceTree = ""; @@ -1394,7 +1391,6 @@ CEEC6B3A2961C4F300D00E1E /* CourseDrawingHomeVC.swift in Sources */, CEB0BCBC29D123350048CCD5 /* GuideView.swift in Sources */, CEC2A6902962B06C00160BF7 /* convertLocationObject.swift in Sources */, - A3C2CADB29E9A12400EC525B /* DeleteAccountVC.swift in Sources */, CEC2A6852961F92C00160BF7 /* CustomButton.swift in Sources */, CE6B63D3296725E6003F900F /* CourseListCVC.swift in Sources */, CEF3CD9A296DB305002723A1 /* CourseDetailResponseDto.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/DeleteAccountVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/DeleteAccountVC.swift deleted file mode 100644 index 4fd4d503..00000000 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/DeleteAccountVC.swift +++ /dev/null @@ -1,119 +0,0 @@ -// -// DeleteAccountVC.swift -// Runnect-iOS -// -// Created by 몽이 누나 on 2023/04/14. -// - -import UIKit - -import SnapKit -import Then - -final class DeleteAccountVC: UIViewController { - - // MARK: - Properties - - // MARK: - UI Components - - private let containerView = UIView().then { - $0.layer.cornerRadius = 15 - } - - private let logoutQuestionLabel = UILabel().then { - $0.text = "정말로 탈퇴하시겠어요?" - $0.font = .b4 - $0.textColor = .g2 - } - - private lazy var yesButton = UIButton(type: .custom).then { - $0.setTitle("네", for: .normal) - $0.titleLabel?.font = .h5 - $0.setTitleColor(.w1, for: .normal) - $0.layer.backgroundColor = UIColor.m1.cgColor - $0.layer.cornerRadius = 10 - } - - private lazy var noButton = UIButton(type: .custom).then { - $0.setTitle("아니오", for: .normal) - $0.titleLabel?.font = .h5 - $0.setTitleColor(.m1, for: .normal) - $0.layer.backgroundColor = UIColor.m3.cgColor - $0.layer.cornerRadius = 10 - } - - // MARK: - View Life Cycle - - override func viewDidLoad() { - super.viewDidLoad() - setUI() - setLayout() - setAddTarget() - } -} - -// MARK: - Methods - -extension DeleteAccountVC { - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - super.touchesBegan(touches, with: event) - if let touch = touches.first, touch.view == self.view { - dismiss(animated: false) - } - } - - private func setAddTarget() { - self.noButton.addTarget(self, action: #selector(touchUpNoButton), for: .touchUpInside) - } -} - -// MARK: - @objc Function - -extension DeleteAccountVC { - @objc func touchUpNoButton() { - dismiss(animated: false) - } -} - -// MARK: - Layout Helpers - -extension DeleteAccountVC { - private func setUI() { - view.backgroundColor = .black.withAlphaComponent(0.8) - containerView.backgroundColor = .w1 - } - - private func setLayout() { - view.addSubviews(containerView) - - containerView.snp.makeConstraints { make in - make.centerX.equalToSuperview() - make.centerY.equalToSuperview() - make.leading.trailing.equalToSuperview().inset(30) - make.height.equalTo(126) - } - - containerView.addSubviews(logoutQuestionLabel, yesButton, noButton) - - logoutQuestionLabel.snp.makeConstraints { make in - make.centerX.equalToSuperview() - make.top.equalToSuperview().offset(26) - } - - noButton.snp.makeConstraints { make in - make.leading.equalToSuperview().offset(16) - make.trailing.equalTo(containerView.snp.centerX).offset(-4) - make.height.equalTo(44) - make.width.equalTo(145) - make.bottom.equalToSuperview().inset(16) - } - - yesButton.snp.makeConstraints { make in - make.trailing.equalToSuperview().inset(16) - make.leading.equalTo(containerView.snp.centerX).offset(4) - make.height.equalTo(44) - make.width.equalTo(145) - make.bottom.equalToSuperview().inset(16) - } - } -} From b57fd37b1e98bcd5c419e17256ae2a6f571bc99d Mon Sep 17 00:00:00 2001 From: Sejin Lee Date: Sat, 29 Apr 2023 14:00:13 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[Feat]=20#129=20-=20=EC=95=A0=ED=94=8C?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EC=9E=85=ED=95=9C=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Router/UserRouter.swift | 13 ++++- .../MyPage/VC/SettingVC/PersonalInfoVC.swift | 55 ++++++++++++++++++- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift index ba8ea315..cd391b6c 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/UserRouter.swift @@ -12,7 +12,7 @@ import Moya enum UserRouter { case getMyPageInfo case updateUserNickname(nickname: String) - case deleteUser + case deleteUser(appleToken: String?) } extension UserRouter: TargetType { @@ -52,7 +52,16 @@ extension UserRouter: TargetType { } var headers: [String: String]? { - return Config.defaultHeader + switch self { + case .deleteUser(let appleToken): + if let appleToken = appleToken { + return ["Content-Type": "application/json", "appleAccessToken": appleToken] + } else { + return Config.defaultHeader + } + default: + return Config.defaultHeader + } } var validationType: ValidationType { diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift index 91223e99..85066225 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/SettingVC/PersonalInfoVC.swift @@ -6,6 +6,7 @@ // import UIKit +import AuthenticationServices import SnapKit import Then @@ -112,7 +113,14 @@ extension PersonalInfoVC { private func pushToDeleteAccountVC() { let deleteAccountVC = RNAlertVC(description: "정말로 탈퇴하시겠어요?") deleteAccountVC.rightButtonTapAction = { [weak self] in - self?.deleteUser() + // 애플 유저가 탈퇴할 경우 애플로부터 토큰을 한번 더 받아서 보내주기 + if let isKakao = UserManager.shared.isKakao, !isKakao { + // 애플 토큰 받기 + self?.requestAppleToken() + } else { + // 카카오 유저 탈퇴 + self?.deleteUser(appleToken: nil) + } } deleteAccountVC.modalPresentationStyle = .overFullScreen self.present(deleteAccountVC, animated: false) @@ -133,6 +141,16 @@ extension PersonalInfoVC { guard let window = self.view.window else { return } ViewControllerUtils.setRootViewController(window: window, viewController: navigationController, withAnimation: true) } + + private func requestAppleToken() { + let appleIDProvider = ASAuthorizationAppleIDProvider() + let request = appleIDProvider.createRequest() + + let authorizationController = ASAuthorizationController(authorizationRequests: [request]) + authorizationController.delegate = self + authorizationController.presentationContextProvider = self + authorizationController.performRequests() + } } // MARK: - Layout Helpers @@ -237,9 +255,9 @@ extension PersonalInfoVC { // MARK: - Network extension PersonalInfoVC { - private func deleteUser() { + private func deleteUser(appleToken: String?) { LoadingIndicator.showLoading() - self.userProvider.request(.deleteUser) { [weak self] result in + self.userProvider.request(.deleteUser(appleToken: appleToken)) { [weak self] result in LoadingIndicator.hideLoading() guard let self = self else { return } switch result { @@ -266,3 +284,34 @@ extension PersonalInfoVC { } } } + +extension PersonalInfoVC: ASAuthorizationControllerPresentationContextProviding, ASAuthorizationControllerDelegate { + func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { + return self.view.window! + } + + /// Apple ID 연동 성공 시 + func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { + switch authorization.credential { + /// Apple ID + case let appleIDCredential as ASAuthorizationAppleIDCredential: + + /// 계정 정보 가져오기 + let userIdentifier = appleIDCredential.user + let idToken = appleIDCredential.identityToken! + guard let tokenStr = String(data: idToken, encoding: .utf8) else { return } + + print("User ID : \(userIdentifier)") + print("token : \(String(describing: tokenStr))") + + self.deleteUser(appleToken: tokenStr) + default: + break + } + } + + /// Apple ID 연동 실패 시 + func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { + print("Apple Login error") + } +}