Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network [#84] 회원 탈퇴 & 로그아웃 API 구현 #85

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
0BA193B62B4D08B7007E3F9C /* ProblemSurveyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA193B52B4D08B7007E3F9C /* ProblemSurveyViewController.swift */; };
0BA193B92B4D4097007E3F9C /* SignUpManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BA193B82B4D4097007E3F9C /* SignUpManager.swift */; };
0BB0AE502B54580D00C647AE /* RefreshTokenResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BB0AE4F2B54580D00C647AE /* RefreshTokenResponseDTO.swift */; };
0BB0AE522B55065300C647AE /* LogoutResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BB0AE512B55065300C647AE /* LogoutResponseDTO.swift */; };
0BB0AE542B55068200C647AE /* RevokeResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BB0AE532B55068200C647AE /* RevokeResponseDTO.swift */; };
0BC0EBD22B493B6B003EF5D4 /* OnboardingProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC0EBD12B493B6B003EF5D4 /* OnboardingProgressView.swift */; };
0BC0EBD42B494459003EF5D4 /* OnboardingSwipeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BC0EBD32B494459003EF5D4 /* OnboardingSwipeView.swift */; };
0BD98DB92B4D671600E35188 /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD98DB82B4D671600E35188 /* SplashViewController.swift */; };
Expand Down Expand Up @@ -253,6 +255,8 @@
0BA193B52B4D08B7007E3F9C /* ProblemSurveyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProblemSurveyViewController.swift; sourceTree = "<group>"; };
0BA193B82B4D4097007E3F9C /* SignUpManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpManager.swift; sourceTree = "<group>"; };
0BB0AE4F2B54580D00C647AE /* RefreshTokenResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshTokenResponseDTO.swift; sourceTree = "<group>"; };
0BB0AE512B55065300C647AE /* LogoutResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutResponseDTO.swift; sourceTree = "<group>"; };
0BB0AE532B55068200C647AE /* RevokeResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RevokeResponseDTO.swift; sourceTree = "<group>"; };
0BC0EBD12B493B6B003EF5D4 /* OnboardingProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingProgressView.swift; sourceTree = "<group>"; };
0BC0EBD32B494459003EF5D4 /* OnboardingSwipeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingSwipeView.swift; sourceTree = "<group>"; };
0BD98DB82B4D671600E35188 /* SplashViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -452,6 +456,8 @@
0B1AE81E2B53ABB700CF5154 /* SignUpRequestDTO.swift */,
0B1AE8202B53ABC400CF5154 /* SignUpResponseDTO.swift */,
0BB0AE4F2B54580D00C647AE /* RefreshTokenResponseDTO.swift */,
0BB0AE512B55065300C647AE /* LogoutResponseDTO.swift */,
0BB0AE532B55068200C647AE /* RevokeResponseDTO.swift */,
);
path = AuthModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -1377,6 +1383,7 @@
0B78174E2B4BD96D0078E925 /* OnboardingBaseViewControllers.swift in Sources */,
3649237D2B4FC9CD00BF7ACA /* NetworkRequest.swift in Sources */,
0B8A89B12B369E4C00688BA6 /* HomeView.swift in Sources */,
0BB0AE522B55065300C647AE /* LogoutResponseDTO.swift in Sources */,
0BFD2FB42B4EE71900C6327F /* SignInCompleteViewController.swift in Sources */,
360D11042B53465B008BE85A /* UIApplication+.swift in Sources */,
3649239B2B505B2600BF7ACA /* Providers.swift in Sources */,
Expand All @@ -1392,6 +1399,7 @@
364C4E712B4BC9780015729C /* AppAddButtonView.swift in Sources */,
360D11022B5343C6008BE85A /* requestPermision.swift in Sources */,
174AF4962B447CE700450D07 /* ChanllengeCells.swift in Sources */,
0BB0AE542B55068200C647AE /* RevokeResponseDTO.swift in Sources */,
17314F832B486BEC0089A551 /* AlertViewController.swift in Sources */,
17314F9D2B4C554D0089A551 /* MypageCollectionViewCell.swift in Sources */,
17314F972B4C42130089A551 /* MyPageView.swift in Sources */,
Expand Down
6 changes: 0 additions & 6 deletions HMH_iOS/HMH_iOS/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
DispatchQueue.main.async{
if UserManager.shared.hasAccessToken {
let provider = Providers.AuthProvider
provider.request(target: .tokenRefresh, instance: BaseResponse<RefreshTokebResponseDTO>.self, viewController: LoginViewController()) { data in
if let data = data.data {
UserManager.shared.updateToken(data.token.accessToken, data.token.accessToken)
}
}
showTabBarViewController()
} else {
showLoginViewController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class UserManager {
var getRefreshToken: String { return self.refreshToken ?? "" }
var getAppleToken: String { return self.appleToken ?? "" }
var getUserIdentifier: String { return self.appleUserIdentifier ?? "" }
var getUserName: String { return self.familyName ?? "" }
var getFamilyName: String { return self.familyName ?? "" }
var getGivenName: String { return self.givenName ?? "" }
var getFullName: String { return self.fullName ?? "여행자" }
var getUserId: Int { return self.userId ?? 0}
Expand Down
2 changes: 2 additions & 0 deletions HMH_iOS/HMH_iOS/Network/Base/NetworkProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class NetworkProvider<Provider : TargetType> : MoyaProvider<Provider> {
print("🚨 decoding Error 발생")
}
} else if response.statusCode == 401 {
print("🚨 401 Error")

let provider = Providers.AuthProvider

provider.request(target: .tokenRefresh, instance: BaseResponse<RefreshTokebResponseDTO>.self, viewController: LoginViewController()) { data in
Expand Down
11 changes: 11 additions & 0 deletions HMH_iOS/HMH_iOS/Network/DTO/AuthModel/LogoutResponseDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// LogoutResponseDTO.swift
// HMH_iOS
//
// Created by Seonwoo Kim on 1/15/24.
//

import Foundation

struct LogoutResponseDTO: Codable {
}
11 changes: 11 additions & 0 deletions HMH_iOS/HMH_iOS/Network/DTO/AuthModel/RevokeResponseDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// RevokeResponseDTO.swift
// HMH_iOS
//
// Created by Seonwoo Kim on 1/15/24.
//

import Foundation

struct RevokeResponseDTO: Codable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ struct CreateChallengeResponseDTO: Codable {

enum CodingKeys: String, CodingKey {
case challengeID = "challengeId"

}
}
3 changes: 3 additions & 0 deletions HMH_iOS/HMH_iOS/Network/Foundation/APIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ extension APIConstants{
auth : accessToken]
static let hasRefreshTokenHeader = [contentType: applicationJSON,
auth : refreshToken]
static let signUpHeader = [contentType: applicationJSON,
auth : appleAccessToken,
OS: iOS,]
}
20 changes: 19 additions & 1 deletion HMH_iOS/HMH_iOS/Network/Router/AuthRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum AuthRouter {
case socialLogin(data: SocialLoginRequestDTO)
case signUp(data: SignUpRequestDTO)
case tokenRefresh
case revoke
case logout
}

extension AuthRouter: BaseTargetType {
Expand All @@ -21,9 +23,13 @@ extension AuthRouter: BaseTargetType {
case .socialLogin:
return APIConstants.hasSocialTokenHeader
case .signUp:
return APIConstants.hasTokenHeader
return APIConstants.signUpHeader
case .tokenRefresh:
return APIConstants.hasRefreshTokenHeader
case .revoke:
return APIConstants.hasTokenHeader
case .logout:
return APIConstants.hasTokenHeader
}
}

Expand All @@ -35,6 +41,10 @@ extension AuthRouter: BaseTargetType {
return "user/signup"
case .tokenRefresh:
return "user/reissue"
case .revoke:
return "user"
case .logout:
return "user/logout"
}
}

Expand All @@ -46,6 +56,10 @@ extension AuthRouter: BaseTargetType {
return .post
case .tokenRefresh:
return .post
case .revoke:
return .delete
case .logout:
return .post
}
}

Expand All @@ -57,6 +71,10 @@ extension AuthRouter: BaseTargetType {
return .requestJSONEncodable(data)
case .tokenRefresh:
return .requestPlain
case .revoke:
return .requestPlain
case .logout:
return .requestPlain
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ final class AlertViewController: UIViewController {

extension AlertViewController: AlertDelegate {
func enabledButtonTapped() {
let provider = Providers.AuthProvider
if alertType == .HMHQuitALert {
provider.request(target: .revoke, instance: BaseResponse<RevokeResponseDTO>.self, viewController: self) { data in
print("revoke!!!!!!")
UserManager.shared.clearData()
}
} else {
let provider = Providers.AuthProvider

provider.request(target: .logout, instance: BaseResponse<LogoutResponseDTO>.self, viewController: self) { data in
print("logout!!!!!!")
Comment on lines +89 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p5. 조금 더 신나게 아이콘을 이용해 프린트 찍는건 어떠신지?
Mino cute _ new journey to the west NJTTW _ #WINNER Song Mino

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아이콘은 지양하겠습니다

UserManager.shared.clearAll()
}
}

dismiss(animated: false) {
let loginViewController = LoginViewController()

Expand All @@ -95,7 +110,6 @@ extension AlertViewController: AlertDelegate {
}
}


func alertDismissTapped() {
dismiss(animated: false) {
(self.okAction ?? self.emptyActions)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,11 @@ extension ApprovePermisionController: NextViewPushDelegate {
}
let nextViewController = AppSelectViewController()
self.navigationController?.pushViewController(nextViewController, animated: false)
let request = SignUpRequestDTO(socialPlatform: "APPLE", name: UserManager.shared.getUserName, onboarding: onboarding, challenge: challenge)
print(request.onboarding.averageUseTime)
let request = SignUpRequestDTO(socialPlatform: "APPLE", name: UserManager.shared.getFullName, onboarding: onboarding, challenge: challenge)

let provider = Providers.AuthProvider
provider.request(target: .signUp(data: request), instance: BaseResponse<SignUpResponseDTO>.self, viewController: self) { data in
if data.status == 403 {
let nextViewController = TimeSurveyViewController()
self.navigationController?.pushViewController(nextViewController, animated: false)
} else if data.status == 200 {
if data.status == 201 {
self.setRootViewController(TabBarController())
guard let data = data.data else { return }
UserManager.shared.updateToken(data.token.accessToken, data.token.refreshToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ final class SplashViewController: UIViewController {

private func setSplashView() {
view.backgroundColor = .background
let provider = Providers.AuthProvider
provider.request(target: .tokenRefresh, instance: BaseResponse<RefreshTokebResponseDTO>.self, viewController: LoginViewController()) { data in
if let data = data.data {
UserManager.shared.updateToken(data.token.accessToken, data.token.accessToken)
print("token",data.token.accessToken,data.token.accessToken)
}
}
}
}