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

๐Ÿ”€ :: (#477) Logout UseCase ์ถ”๊ฐ€ #486

Merged
merged 2 commits into from
Apr 14, 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
17 changes: 16 additions & 1 deletion Projects/App/Sources/Application/AppComponent+Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public extension AppComponent {
RequestComponent(parent: self)
}

var localAuthDataSource: any LocalAuthDataSource {
shared {
LocalAuthDataSourceImpl(keychain: keychain)
}
}

var remoteAuthDataSource: any RemoteAuthDataSource {
shared {
RemoteAuthDataSourceImpl(keychain: keychain)
Expand All @@ -40,7 +46,10 @@ public extension AppComponent {

var authRepository: any AuthRepository {
shared {
AuthRepositoryImpl(remoteAuthDataSource: remoteAuthDataSource)
AuthRepositoryImpl(
localAuthDataSource: localAuthDataSource,
remoteAuthDataSource: remoteAuthDataSource
)
}
}

Expand All @@ -55,4 +64,10 @@ public extension AppComponent {
FetchNaverUserInfoUseCaseImpl(authRepository: authRepository)
}
}

var logoutUseCase: any LogoutUseCase {
shared {
LogoutUseCaseImpl(authRepository: authRepository)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol LocalAuthDataSource {
func logout()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import RxSwift
public protocol AuthRepository {
func fetchToken(token: String, type: ProviderType) -> Single<AuthLoginEntity>
func fetchNaverUserInfo(tokenType: String, accessToken: String) -> Single<NaverUserInfoEntity>
func logout() -> Completable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol LogoutUseCase {
func execute() -> Completable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import AuthDomainInterface
import KeychainModule
import RxSwift
import Utility

public final class LocalAuthDataSourceImpl: LocalAuthDataSource {
private let keychain: any Keychain

public init(keychain: any Keychain) {
self.keychain = keychain
}

public func logout() {
keychain.delete(type: .accessToken)
keychain.delete(type: .refreshToken)
keychain.delete(type: .accessExpiresIn)
PreferenceManager.userInfo = nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import AuthDomainInterface
import RxSwift

public final class AuthRepositoryImpl: AuthRepository {
private let localAuthDataSource: any LocalAuthDataSource
private let remoteAuthDataSource: any RemoteAuthDataSource

public init(remoteAuthDataSource: RemoteAuthDataSource) {
public init(
localAuthDataSource: any LocalAuthDataSource,
remoteAuthDataSource: any RemoteAuthDataSource
) {
self.localAuthDataSource = localAuthDataSource
self.remoteAuthDataSource = remoteAuthDataSource
}

Expand All @@ -23,4 +28,12 @@ public final class AuthRepositoryImpl: AuthRepository {
public func fetchNaverUserInfo(tokenType: String, accessToken: String) -> Single<NaverUserInfoEntity> {
remoteAuthDataSource.fetchNaverUserInfo(tokenType: tokenType, accessToken: accessToken)
}

public func logout() -> Completable {
Completable.create { [localAuthDataSource] observer in
localAuthDataSource.logout()
observer(.completed)
return Disposables.create()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AuthDomainInterface
import RxSwift

public struct LogoutUseCaseImpl: LogoutUseCase {
private let authRepository: any AuthRepository

public init(authRepository: any AuthRepository) {
self.authRepository = authRepository
}

public func execute() -> Completable {
authRepository.logout()
}
}
Loading