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

FEAT :: [#324] Splash 뷰 구현 #328

Merged
merged 12 commits into from
May 15, 2024
1 change: 1 addition & 0 deletions Projects/Core/Sources/Coordinator/Setp/AppStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum MGStep: Step {
case TabBarIsRequired

// Auth
case authSplashIsRequired
case authIntroIsRequired
case authAgreeIsRequired
case authNickNameIsRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AuthStepper: Stepper {
public var steps = PublishRelay<Step>()

public var initialStep: Step {
return MGStep.authIntroIsRequired
return MGStep.authSplashIsRequired
}

public init() {
Expand Down
6 changes: 5 additions & 1 deletion Projects/Data/Sources/Repository/AuthRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public class AuthRepository: AuthRepositoryInterface {
public func oauthRecovery(accessToken: String, oauth: OauthType) -> Single<Response> {
return networkService.oauthRecovery(accessToken: accessToken, oauth: oauth)
}


public func tokenReIssue(refreshToken: String) -> Single<Response> {
return networkService.tokenReIssue(refreshToken: refreshToken)
}

public func nicknameCheck(nickname: String) -> Single<Response> {
return networkService.nicknameCheck(nickname: nickname)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public protocol AuthRepositoryInterface {
func oauthSignup(nickname: String, accessToken: String, oauth: OauthType) -> Single<Response>
func oauthLogin(accessToken: String, oauth: OauthType) -> Single<Response>
func oauthRecovery(accessToken: String, oauth: OauthType) -> Single<Response>
func tokenReIssue(refreshToken: String) -> Single<Response>
func nicknameCheck(nickname: String) -> Single<Response>
func getIntroData() -> Single<IntroModel>
}
39 changes: 39 additions & 0 deletions Projects/Domain/Sources/UseCase/AuthUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public protocol AuthUseCase {
func appleButtonTap()
func nextButtonTap() -> Bool
func getIntroData()
func tokenReIssue()
var appleSignupResult: PublishSubject<String> { get }
var introData: PublishSubject<IntroModel> { get }
}
Expand Down Expand Up @@ -86,6 +87,44 @@ extension DefaultAuthUseCase: AuthUseCase {
})
.disposed(by: disposeBag)
}

public func tokenReIssue() {
let refreshToken = TokenManagerImpl().get(key: .refreshToken)
guard let refreshToken = refreshToken else {
AuthStepper.shared.steps.accept(MGStep.authIntroIsRequired)
return
}
authRepository.tokenReIssue(refreshToken: refreshToken)
.flatMap { response -> Single<Response> in
switch response.statusCode {
case 200:
return Single.just(response)
case 401:
return Single.error(AuthErrorType.error401)
case 500:
return Single.error(AuthErrorType.error500)
default:
return Single.just(response)
}
}
.subscribe(onSuccess: { element in
MGLogger.debug("token ReIssue ✅ \(String(describing: element.response))")
if let headers = element.response?.headers {
let accessToken = headers.value(for: "Authorization")?.replacingOccurrences(of: "Bearer ", with: "")
let refreshToken = headers["Set-Cookie"]?.components(separatedBy: ";").first(where: { $0.contains("RF-TOKEN") })?.replacingOccurrences(of: "RF-TOKEN=", with: "")
if let accessToken = accessToken {
TokenManagerImpl().save(token: accessToken, with: .accessToken)
}
if let refreshToken = refreshToken {
TokenManagerImpl().save(token: refreshToken, with: .refreshToken)
}
}
AuthStepper.shared.steps.accept(MGStep.initialization)
}, onFailure: { error in
MGLogger.debug("token ReIssue ❌ \(error)")
AuthStepper.shared.steps.accept(MGStep.authIntroIsRequired)
}).disposed(by: disposeBag)
}
}

extension DefaultAuthUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// }
// return false
// }
//

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
KakaoSDK.initSDK(appKey: "dcfcd3ab4a997c5a53e2ab26a8ec2a63")
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

mainFlow = AuthFlow()

coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.authIntroIsRequired))
coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.authSplashIsRequired))
Flows.use(mainFlow, when: .created) { root in
self.window?.rootViewController = root
self.window?.makeKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@ import Core
public class SplashViewController: BaseViewController<SplashViewModel>, Stepper {

private let iconImageView = UIImageView().then {
$0.image = DSKitAsset.Assets.bodySplitSqt.image
$0.image = DSKitAsset.Assets.splashLogo.image
}

// public override func viewDidAppear(_ animated: Bool) {
// AuthStepper.shared.steps.accept(MGStep.authIntroIsRequired)
// }

public override func attribute() {
super.attribute()
}

public override func layout() {
super.layout()
view.addSubviews([iconImageView])

iconImageView.snp.makeConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ public class SplashViewModel: AuthViewModelType {

public struct Output {}


public init(authUseCase: AuthUseCase) {
self.useCase = authUseCase
self.disposeBag = DisposeBag()

useCase.tokenReIssue()
}

public func transform(_ input: Input, action: (Output) -> Void) -> Output {

let ouput = Output()
action(ouput)

// useCase.appleSignupResult()

return Output()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "splashLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions Projects/Modules/MGFlow/Sources/Flow/AuthFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class AuthFlow: Flow {
var authService: DefaultAuthService!
var authRepository: AuthRepository!
var useCase: DefaultAuthUseCase!
var viewModel: IntroViewModel!
var viewController: IntroViewController!
var viewModel: SplashViewModel!
var viewController: SplashViewController!

public var root: Presentable {
return self.rootViewController
Expand All @@ -33,8 +33,10 @@ public class AuthFlow: Flow {
public func navigate(to step: Step) -> FlowContributors {
guard let step = step as? MGStep else { return .none }
switch step {
case .authIntroIsRequired:
case .authSplashIsRequired:
return setupAuthMainScreen()
case .authIntroIsRequired:
return navigateToIntroViewScreen()
case .authAgreeIsRequired:
return navigateToAgreeViewScreen()
case .authNickNameIsRequired:
Expand All @@ -54,11 +56,11 @@ public class AuthFlow: Flow {
authService = DefaultAuthService()
authRepository = AuthRepository(networkService: authService)
useCase = DefaultAuthUseCase(authRepository: authRepository)
viewModel = IntroViewModel(authUseCase: useCase)
viewModel = SplashViewModel(authUseCase: useCase)
}

private func setupViewController() {
viewController = IntroViewController(viewModel)
viewController = SplashViewController(viewModel)
rootViewController = UINavigationController(rootViewController: viewController)
}

Expand All @@ -67,6 +69,13 @@ public class AuthFlow: Flow {
rootViewController.setViewControllers([viewController], animated: false)
return .one(flowContributor: .contribute(withNextPresentable: self.root, withNextStepper: AuthStepper.shared))
}

private func navigateToIntroViewScreen() -> FlowContributors {
let vc = IntroViewController(IntroViewModel(authUseCase: self.useCase))
rootViewController.pushViewController(vc, animated: false)
vc.navigationItem.hidesBackButton = true
return .none
}

private func navigateToAgreeViewScreen() -> FlowContributors {
let vc = AgreeViewController(AgreeViewModel(useCase: self.useCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public protocol AuthService {
func oauthLogin(accessToken: String, oauth: OauthType) -> Single<Response>
func oauthSingup(nickname: String, accessToken: String, oauth: OauthType) -> Single<Response>
func oauthRecovery(accessToken: String, oauth: OauthType) -> Single<Response>
func tokenReIssue(refreshToken: String) -> Single<Response>
func kakaoButtonTap() -> Single<OAuthToken?>
func requestToken() -> Single<Bool>
func requestIntroData() -> Single<IntroModel>
Expand Down Expand Up @@ -75,6 +76,10 @@ extension DefaultAuthService: AuthService {
}
}

public func tokenReIssue(refreshToken: String) -> Single<Response> {
return authProvider.rx.request(.reissuanceToken(refreshToken: refreshToken))
}

public func kakaoButtonTap() -> Single<OAuthToken?> {
return Single.create { single in
if UserApi.isKakaoTalkLoginAvailable() {
Expand Down
Loading