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

[IDLE-000] 센터 관리자 인증 과정 누락 문제 해결 #98

Merged
merged 6 commits into from
Oct 31, 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
4 changes: 4 additions & 0 deletions project/Projects/Data/DataSource/API/AuthAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,8 @@ extension AuthAPI: BaseAPI {
return .requestPlain
}
}

public var validationType: ValidationType {
.successCodes
}
}
33 changes: 14 additions & 19 deletions project/Projects/Data/DataSource/Service/BaseNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,6 @@ public class BaseNetworkService<TagetAPI: BaseAPI>: NetworkService {
completion(.success(adaptedRequest))
}

private let tokenSession: Session = {

let configuration = URLSessionConfiguration.default

// 단일 요청이 완료되는데 걸리는 최대 시간, 초과시 타임아웃
configuration.timeoutIntervalForRequest = 10

// 하나의 리소스를 로드하는데 걸리는 시간, 재시도를 포함한다 초과시 타임아웃
configuration.timeoutIntervalForResource = 10

// Cache policy: 로컬캐시를 무시하고 항상 새로운 데이터를 가져온다.
configuration.requestCachePolicy = .reloadIgnoringLocalCacheData

let session = Session(configuration: configuration)

return session
}()

lazy var tokenRetrier = Retrier { [weak self] request, session, error, completion in

if let httpResponse = request.response {
Expand Down Expand Up @@ -196,7 +178,9 @@ public extension BaseNetworkService {
.request(api)
.catch { error in

let moyaError = error as! MoyaError
guard let moyaError = error as? MoyaError else {
return .error(error)
}

// 재시도 실패 or 근본적인 에러(Ex 타임아웃, 네트워크 끊어짐)
if case let .underlying(error, response) = moyaError {
Expand All @@ -210,6 +194,17 @@ public extension BaseNetworkService {
HTTPResponseException(response: response)
)
}

// 401코드의 경우 별도처리, Moya 인증상태 오류의 경우 underlyng으로 랩핑
if case .responseValidationFailed(let reason) = afError {

if case . unacceptableStatusCode = reason, let response {

return .error(
HTTPResponseException(response: response)
)
}
}
}

// 근본적인 문제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DefaultAuthUseCase: AuthUseCase {
// 센터 회원가입 실행
public func registerCenterAccount(registerState: CenterRegisterState) -> Single<Result<Void, DomainError>> {

// #1. 회원가입 실행
// 회원가입 실행
let registerResult = authRepository
.requestRegisterCenterAccount(
managerName: registerState.name,
Expand All @@ -35,27 +35,8 @@ public class DefaultAuthUseCase: AuthUseCase {
id: registerState.id,
password: registerState.password
)
.asObservable()
.share()

let registerSuccess = registerResult.compactMap { $0.value }
let registerFailure = registerResult.compactMap { $0.error }

let afterRegisterTaskResult = registerSuccess
.map { [userInfoLocalRepository] _ in
// #2. 유저정보 로컬에 저장
userInfoLocalRepository.updateUserType(.center)
}
.flatMap { [notificationTokenUseCase] _ in
// #3. 원격알림 토큰을 서버에 전송
notificationTokenUseCase.setNotificationToken()
}

return Observable.merge(
afterRegisterTaskResult,
registerFailure.asObservable()
.map { error -> Result<Void, DomainError> in .failure(error) }
).asSingle()
return registerResult
}

// 센터 로그인 실행
Expand Down
14 changes: 7 additions & 7 deletions project/Projects/Domain/Sources/Entity/Error/DomainError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ public enum DomainError: Error, Equatable {
public var message: String {
switch self {
case .invalidParameter:
return "요청하신 API에서 잘못된 파라미터가 입력되었습니다. 입력값을 다시 확인해주세요."
return "입력값을 다시 확인해주세요."

case .unAuthorizedRequest:
return "접근 권한이 없습니다. 로그인이 필요한 API에 접근하려면 로그인을 먼저 해주세요."
return "로그인을 먼저 해주세요."

case .invalidLoginRequest:
return "로그인 실패: 입력하신 ID 또는 비밀번호가 잘못되었습니다. 존재하지 않는 ID로 로그인 시도 시에도 발생할 수 있습니다."
return "입력하신 아이디 또는 비밀번호가 잘못되었습니다."

case .invalidPassword:
return "비밀번호가 일치하지 않습니다. 정확한 비밀번호를 입력해주세요. (예: 회원 탈퇴 시 비밀번호 입력 단계에서 발생)"
return "비밀번호가 일치하지 않습니다. 정확한 비밀번호를 입력해주세요."

case .unregisteredUser:
return "등록되지 않은 사용자입니다. 회원가입이 필요합니다."
Expand All @@ -153,7 +153,7 @@ public enum DomainError: Error, Equatable {
return "유효하지 않은 토큰입니다. 토큰의 값이 올바른지 다시 확인해주세요."

case .tokenExpiredException:
return "토큰이 만료되었습니다. 다시 로그인해주세요."
return "로그인 지속시간을 초과했습니다. 다시 로그인해주세요."

case .tokenNotFound:
return "토큰을 찾을 수 없습니다. 요청을 다시 확인해주세요."
Expand Down Expand Up @@ -189,10 +189,10 @@ public enum DomainError: Error, Equatable {
return "요청하신 리소스를 찾을 수 없습니다. 요청이 올바른지 다시 확인해주세요."

case .clientException:
return "SMS 발송에 실패했습니다. 입력된 정보를 다시 확인하거나 나중에 다시 시도해주세요."
return "인증번호 메세지 발송에 실패했습니다."

case .businessCodeNotFound:
return "사업자 등록번호를 찾을 수 없습니다. 정확한 정보를 입력했는지 확인해주세요."
return "사업자 등록번호를 찾을 수 없습니다."

case .geoCodingFailure:
return "입력된 주소로 지리 정보를 찾을 수 없습니다. 주소를 다시 확인해주세요."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
2 changes: 0 additions & 2 deletions project/Projects/Presentation/Feature/Auth/Resources/Empty.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import PresentationCore
import Core

public enum CenterAccountRegisterCoordinatorDestination {
case centerMainPage
case centerAuthPage
}

public class CenterAccountRegisterCoordinator: Coordinator {
Expand Down Expand Up @@ -61,7 +61,7 @@ public class CenterAccountRegisterCoordinator: Coordinator {
completeButtonText: "시작하기") { [weak self] in

// 메인페이지로 이동
self?.startFlow(.centerMainPage)
self?.startFlow(.centerAuthPage)
}

// 완료화면으로 이동
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension CenterAccountRegisterViewModel {
}
.share()

output.idDuplicationCheckResult = idDuplicationCheckResult
let isIdDuplicated = idDuplicationCheckResult
.map { result in
switch result {
case .success:
Expand All @@ -136,8 +136,27 @@ extension CenterAccountRegisterViewModel {
return false
}
}
.share()

output.idDuplicationCheckResult = isIdDuplicated
.asDriver(onErrorDriveWith: .never())

isIdDuplicated
.unretained(self)
.subscribe(onNext: { (vm, result) in

let alertObject: DefaultAlertObject = .init()
alertObject.setTitle(
result ? "사용가능한 id입니다." : "사용불가한 id입니다."
)
alertObject.addAction(
.init(titleName: "닫기", action: nil)
)

vm.presentAlert?(alertObject)
})
.disposed(by: disposeBag)

let idDuplicationFailure = idDuplicationCheckResult.compactMap { $0.error }

idDuplicationFailure
Expand Down Expand Up @@ -269,6 +288,7 @@ extension CenterAccountRegisterViewModel {
return authUseCase
.loginCenterAccount(id: id, password: pw)
}
.share()

let loginSuccess = loginResult.compactMap { $0.value }
let loginFailure = loginResult.compactMap { $0.error }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ValidationIndicator: UIView {
let animateDuration: TimeInterval = animated ? 0.2 : 0

UIView.transition(with: self, duration: animateDuration, options: .transitionCrossDissolve) {
self.iconView.image = state == .valid ? AuthFeatureAsset.vsMark.image : AuthFeatureAsset.vfMark.image
self.iconView.image = state == .valid ? DSKitAsset.Icons.vsMark.image : DSKitAsset.Icons.vfMark.image
}

UIView.animate(withDuration: animateDuration) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Core

public enum CenterLogInCoordinatorDestination {
case centerMainPage
case centerCertificatePage
case makeCenterProfilePage
}

public class CenterLogInCoordinator: BaseCoordinator {
Expand All @@ -26,15 +28,25 @@ public class CenterLogInCoordinator: BaseCoordinator {
public override func start() {

let viewModel = CenterLoginViewModel()
viewModel.presentCenterMainPage = { [weak self] in
self?.startFlow(.centerMainPage)
viewModel.exitPage = { [weak self] in
self?.router.popModule(animated: true)
}
viewModel.presentAlert = { [weak self] object in
self?.router.presentDefaultAlertController(object: object)
}
viewModel.presentSetupNewPasswordPage = { [weak self] in
self?.startSetupNewPasswordFlow()
}
viewModel.exitPage = { [weak self] in
self?.router.popModule(animated: true)
viewModel.presentCenterMainPage = { [weak self] in
self?.startFlow(.centerMainPage)
}
viewModel.presentCertificatePage = { [weak self] in
self?.startFlow(.centerCertificatePage)
}
viewModel.presentMakeCenterProfilePage = { [weak self] in
self?.startFlow(.makeCenterProfilePage)
}

let viewController = CenterLoginViewController(viewModel: viewModel)

router.push(module: viewController, animated: true) { [weak self] in
Expand Down
Loading
Loading