Skip to content

Commit fae35af

Browse files
authored
[#302] FCM토큰이 유효하지 않을 때, 에러가 뜨고 로컬 세션이 유지되는 이슈를 해결한다 (#303)
* feat: CurrentValueSubject를 통해 FirebaseAuth의 세션이 상시 반영되도록 추가 * refactor: 기존 수동으로 세션 처리하는 로직 제거 * feat: 로그인 세션을 FirebaseAuth 기준으로 일원화
1 parent ad9c547 commit fae35af

21 files changed

Lines changed: 44 additions & 233 deletions

DevLog/App/Assembler/DataAssembler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ final class DataAssembler: Assembler {
3434

3535
container.register(AuthSessionRepository.self) {
3636
AuthSessionRepositoryImpl(
37-
authService: container.resolve(AuthService.self),
38-
userDefaultsStore: container.resolve(UserDefaultsStore.self)
37+
authService: container.resolve(AuthService.self)
3938
)
4039
}
4140

DevLog/App/Assembler/DomainAssembler.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,6 @@ private extension DomainAssembler {
139139
UpdateSystemThemeUseCaseImpl(container.resolve(UserPreferencesRepository.self))
140140
}
141141

142-
container.register(FetchFirstLaunchUseCase.self) {
143-
FetchFirstLaunchUseCaseImpl(container.resolve(UserPreferencesRepository.self))
144-
}
145-
146-
container.register(UpdateFirstLaunchUseCase.self) {
147-
UpdateFirstLaunchUseCaseImpl(container.resolve(UserPreferencesRepository.self))
148-
}
149-
150142
container.register(FetchRecentSearchQueriesUseCase.self) {
151143
FetchRecentSearchQueriesUseCaseImpl(container.resolve(UserPreferencesRepository.self))
152144
}

DevLog/App/DevLogApp.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ struct DevLogApp: App {
2020
WindowGroup {
2121
RootView(viewModel: RootViewModel(
2222
sessionUseCase: container.resolve(AuthSessionUseCase.self),
23-
signOutUseCase: container.resolve(SignOutUseCase.self),
24-
fetchFirstLaunchUseCase: container.resolve(FetchFirstLaunchUseCase.self),
25-
updateFirstLaunchUseCase: container.resolve(UpdateFirstLaunchUseCase.self),
26-
observeSystemThemeUseCase: container.resolve(ObserveSystemThemeUseCase.self),
27-
updateSystemThemeUseCase: container.resolve(UpdateSystemThemeUseCase.self)
23+
observeSystemThemeUseCase: container.resolve(ObserveSystemThemeUseCase.self)
2824
))
2925
.autocorrectionDisabled()
3026
}

DevLog/App/RootView.swift

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,19 @@ struct RootView: View {
1616
ZStack {
1717
Color(UIColor.systemGroupedBackground).ignoresSafeArea()
1818
if let signIn = viewModel.state.signIn {
19-
if signIn && !viewModel.state.isFirstLaunch {
19+
if signIn {
2020
MainView(viewModel: MainViewModel(
2121
observeUnreadPushCountUseCase: container.resolve(ObserveUnreadPushCountUseCase.self)
2222
))
2323
} else {
2424
LoginView(viewModel: LoginViewModel(
25-
signInUseCase: container.resolve(SignInUseCase.self),
26-
signOutUseCase: container.resolve(SignOutUseCase.self),
27-
sessionUseCase: container.resolve(AuthSessionUseCase.self))
25+
signInUseCase: container.resolve(SignInUseCase.self))
2826
)
29-
.onAppear {
30-
viewModel.send(.onAppear)
31-
}
32-
}
33-
} else {
34-
Color.clear.onAppear {
35-
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
36-
if viewModel.state.signIn == nil {
37-
viewModel.send(.setFirstLaunch(true))
38-
viewModel.send(.signOutAuto)
39-
}
40-
}
4127
}
4228
}
4329
}
4430
.preferredColorScheme(viewModel.state.theme.colorScheme)
31+
.onAppear { viewModel.send(.onAppear) }
4532
.alert(viewModel.state.alertTitle, isPresented: Binding(
4633
get: { viewModel.state.showAlert },
4734
set: { viewModel.send(.setAlert($0)) }
@@ -50,12 +37,6 @@ struct RootView: View {
5037
} message: {
5138
Text(viewModel.state.alertMessage)
5239
}
53-
.onChange(of: viewModel.state.isFirstLaunch) { _, newValue in
54-
if newValue {
55-
viewModel.send(.setFirstLaunch(false))
56-
viewModel.send(.signOutAuto)
57-
}
58-
}
5940
.sheet(item: $selectedRoute) { route in
6041
switch route {
6142
case .todoDetail(let todoId):

DevLog/Data/Repository/AuthSessionRepositoryImpl.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,12 @@ import Combine
99

1010
final class AuthSessionRepositoryImpl: AuthSessionRepository {
1111
private let authService: AuthService
12-
private let userDefaultsStore: UserDefaultsStore
1312

14-
init(authService: AuthService, userDefaultsStore: UserDefaultsStore) {
13+
init(authService: AuthService) {
1514
self.authService = authService
16-
self.userDefaultsStore = userDefaultsStore
17-
self.signIn = authService.uid != nil
1815
}
1916

20-
@Published private var signIn: Bool = false
21-
2217
var signedInPublisher: AnyPublisher<Bool, Never> {
23-
$signIn.eraseToAnyPublisher()
24-
}
25-
26-
func setSession(_ signedIn: Bool) {
27-
if !signedIn {
28-
userDefaultsStore.removeAll()
29-
}
30-
self.signIn = signedIn
18+
authService.signedInPublisher
3119
}
3220
}

DevLog/Data/Repository/AuthenticationRepositoryImpl.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,21 @@ final class AuthenticationRepositoryImpl: AuthenticationRepository {
4444
let providerID = try await authService.getProviderID(),
4545
let provider = AuthProvider(rawValue: providerID)
4646
else {
47-
throw AuthError.notAuthenticated
47+
try await authService.clearCurrentSession()
48+
return
4849
}
4950

50-
switch provider {
51-
case .apple:
52-
try await appleAuthService.signOut(uid)
53-
case .github:
54-
try await githubAuthService.signOut(uid)
55-
case .google:
56-
try await googleAuthService.signOut(uid)
51+
do {
52+
switch provider {
53+
case .apple:
54+
try await appleAuthService.signOut(uid)
55+
case .github:
56+
try await githubAuthService.signOut(uid)
57+
case .google:
58+
try await googleAuthService.signOut(uid)
59+
}
60+
} catch AuthError.notAuthenticated {
61+
try await authService.clearCurrentSession()
5762
}
5863
}
5964

DevLog/Data/Repository/UserPreferencesRepositoryImpl.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import Combine
1111
final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
1212
private enum Key {
1313
static let theme = "theme"
14-
static let firstLaunch = "isFirstLaunch"
1514
static let recentQueries = "Search.recentQueries"
1615
static let pushSortOrder = "PushNotification.sortOption"
1716
static let pushTimeFilter = "PushNotification.timeFilter"
@@ -50,17 +49,6 @@ final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
5049
themeStore.send(theme)
5150
}
5251

53-
func isFirstLaunch() -> Bool {
54-
if store.string(forKey: Key.firstLaunch) == nil {
55-
return true
56-
}
57-
return store.bool(forKey: Key.firstLaunch)
58-
}
59-
60-
func setFirstLaunch(_ value: Bool) {
61-
store.setBool(value, forKey: Key.firstLaunch)
62-
}
63-
6452
func recentSearchQueries() -> [String] {
6553
store.stringArray(forKey: Key.recentQueries)
6654
}

DevLog/Domain/Protocol/AuthSessionRepository.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ import Combine
99

1010
protocol AuthSessionRepository {
1111
var signedInPublisher: AnyPublisher<Bool, Never> { get }
12-
func setSession(_ signedIn: Bool)
1312
}

DevLog/Domain/Protocol/UserPreferencesRepository.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ protocol UserPreferencesRepository {
1313
func systemTheme() -> SystemTheme
1414
func setSystemTheme(_ theme: SystemTheme)
1515

16-
func isFirstLaunch() -> Bool
17-
func setFirstLaunch(_ value: Bool)
18-
1916
func recentSearchQueries() -> [String]
2017
func setRecentSearchQueries(_ queries: [String])
2118

DevLog/Domain/UseCase/Auth/Session/AuthSessionUseCase.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ import Combine
99

1010
protocol AuthSessionUseCase {
1111
var signedInPublisher: AnyPublisher<Bool, Never> { get }
12-
func execute(_ signIn: Bool)
1312
}

0 commit comments

Comments
 (0)