Skip to content
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
5 changes: 4 additions & 1 deletion DevLog/App/Assembler/DataAssembler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ final class DataAssembler: Assembler {
}

container.register(AuthSessionRepository.self) {
AuthSessionRepositoryImpl(authService: container.resolve(AuthService.self))
AuthSessionRepositoryImpl(
authService: container.resolve(AuthService.self),
userDefaultsStore: container.resolve(UserDefaultsStore.self)
)
}

container.register(AuthDataRepository.self) {
Expand Down
7 changes: 6 additions & 1 deletion DevLog/Data/Repository/AuthSessionRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import Combine

final class AuthSessionRepositoryImpl: AuthSessionRepository {
private let authService: AuthService
private let userDefaultsStore: UserDefaultsStore

init(authService: AuthService) {
init(authService: AuthService, userDefaultsStore: UserDefaultsStore) {
self.authService = authService
self.userDefaultsStore = userDefaultsStore
self.signIn = authService.uid != nil
}

Expand All @@ -22,6 +24,9 @@ final class AuthSessionRepositoryImpl: AuthSessionRepository {
}

func setSession(_ signedIn: Bool) {
if !signedIn {
userDefaultsStore.removeAll()
}
self.signIn = signedIn
}
}
5 changes: 5 additions & 0 deletions DevLog/Storage/Persistence/UserDefaultsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ final class UserDefaultsStore {
func setBool(_ value: Bool, forKey key: String) {
userDefaults.set(value, forKey: key)
}

func removeAll() {
guard let bundleIdentifier = Bundle.main.bundleIdentifier else { return }
userDefaults.removePersistentDomain(forName: bundleIdentifier)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

removePersistentDomain(forName:) 메서드 호출 후에는 변경 사항이 즉시 반영되지 않을 수 있습니다. Apple의 removePersistentDomain(forName:) 공식 문서에서는 이 메서드 호출 후 synchronize()를 호출하여 변경 사항을 디스크에 동기화할 것을 권장하고 있습니다. 로그아웃 시 사용자 데이터가 즉시 확실하게 삭제되도록 보장하기 위해 synchronize() 호출을 추가하는 것이 더 안전합니다.

        userDefaults.removePersistentDomain(forName: bundleIdentifier)
        userDefaults.synchronize()

}
}