File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,8 +22,10 @@ public struct DataAssembly: Assembly {
2222 container. register (
2323 type: AuthStateRepository . self
2424 ) { _ in
25+ @Autowired ( name: " oauth " ) var networkProvider : NetworkProvider
2526 @Autowired var tokenProvider : TokenProvider
2627 return DefaultAuthStateRepository (
28+ networkProvider: networkProvider,
2729 tokenProvider: tokenProvider
2830 )
2931 }
Original file line number Diff line number Diff line change @@ -5,9 +5,14 @@ import Combine
55import Foundation
66
77public struct DefaultAuthStateRepository : AuthStateRepository {
8+ private let networkProvider : NetworkProvider
89 private let tokenProvider : TokenProvider
910
10- public init ( tokenProvider: TokenProvider ) {
11+ public init (
12+ networkProvider: NetworkProvider ,
13+ tokenProvider: TokenProvider
14+ ) {
15+ self . networkProvider = networkProvider
1116 self . tokenProvider = tokenProvider
1217 }
1318
@@ -16,8 +21,13 @@ public struct DefaultAuthStateRepository: AuthStateRepository {
1621 . eraseToAnyPublisher ( )
1722 }
1823
19- public func accessToken( ) -> AnyPublisher < String ? , Never > {
20- return Just ( tokenProvider. accessToken)
21- . eraseToAnyPublisher ( )
24+ public func validate( ) -> AnyPublisher < Void , AuthError > {
25+ networkProvider. request (
26+ target: AuthAPI . me,
27+ type: EmptyResponse . self
28+ )
29+ . mapError { _ in AuthError . missingToken }
30+ . map { _ in }
31+ . eraseToAnyPublisher ( )
2232 }
2333}
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ import Combine
44
55public protocol AuthStateRepository {
66 func isLoggedIn( ) -> AnyPublisher < Bool , Never >
7- func accessToken ( ) -> AnyPublisher < String ? , Never >
7+ func validate ( ) -> AnyPublisher < Void , AuthError >
88}
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Combine
44import Foundation
55
66/// 인증 상태를 체크합니다.
7- /// 단순히 AccessToken 여부를 체크하는 간단한 UseCase로 에러는 방출하지 않습니다 .
7+ /// 내부에 AccessToken이 있는지 확인하고, 서버로 보내 검증합니다 .
88public protocol AuthStateUseCase {
9- func execute( ) -> AnyPublisher < Bool , Never >
9+ func execute( ) -> AnyPublisher < Void , AuthError >
1010}
Original file line number Diff line number Diff line change 11// Copyright © 2025 Booket. All rights reserved
22
3+ import BKCore
34import Combine
45import Foundation
56
@@ -10,9 +11,13 @@ public struct DefaultAuthStateUseCase: AuthStateUseCase {
1011 self . authStateRepository = authStateRepository
1112 }
1213
13- public func execute( ) -> AnyPublisher < Bool , Never > {
14+ public func execute( ) -> AnyPublisher < Void , AuthError > {
1415 authStateRepository
1516 . isLoggedIn ( )
17+ . flatMap { _ in
18+ authStateRepository. validate ( )
19+ }
20+ . debugError ( logger: AppLogger . auth)
1621 . eraseToAnyPublisher ( )
1722 }
1823}
Original file line number Diff line number Diff line change @@ -23,13 +23,15 @@ public final class AppCoordinator: Coordinator {
2323
2424 public func start( ) {
2525 authStateUseCase. execute ( )
26- . sink { [ weak self] isLoggedIn in
27- if isLoggedIn {
26+ . receive ( on: DispatchQueue . main)
27+ . sink ( receiveCompletion: { [ weak self] completion in
28+ switch completion {
29+ case . finished:
2830 self ? . startMainFlow ( )
29- } else {
31+ case . failure :
3032 self ? . startAuthFlow ( )
3133 }
32- }
34+ } , receiveValue : { _ in } )
3335 . store ( in: & cancellable)
3436 }
3537
You can’t perform that action at this time.
0 commit comments