diff --git a/Services/AuthService/Sources/Data/Remote/API/AuthAPI.swift b/Services/AuthService/Sources/Data/Remote/API/AuthAPI.swift index 95c04613..80450752 100644 --- a/Services/AuthService/Sources/Data/Remote/API/AuthAPI.swift +++ b/Services/AuthService/Sources/Data/Remote/API/AuthAPI.swift @@ -6,6 +6,7 @@ import XEnvironment enum AuthAPI: TargetType { case signin(request: SigninRequest) case signup(request: SignupRequest) + case logout(accessToken: String) case refreshToken(refreshToken: String) } @@ -19,7 +20,7 @@ extension AuthAPI { switch self { case .signin, .refreshToken: return "/users/login" - case .signup: + case .signup, .logout: return "/users" } } @@ -28,7 +29,7 @@ extension AuthAPI { switch self { case .signin, .signup: return .post - case .refreshToken: + case .refreshToken, .logout: return .put } } @@ -52,6 +53,8 @@ extension AuthAPI { switch self { case .refreshToken(let refreshToken): return ["Refresh-Token": "Bearer \(refreshToken)"] + case .logout(let accessToken): + return ["Authorization": "Bearer \(accessToken)"] default: return nil } diff --git a/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSource.swift b/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSource.swift index baa27f62..60d8d269 100644 --- a/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSource.swift +++ b/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSource.swift @@ -5,5 +5,6 @@ import RxSwift protocol RemoteAuthDataSource { func signin(request: SigninRequest) -> Single func signup(request: SignupRequest) -> Completable + func logout(accessToken: String) -> Completable func refreshToken(refreshToken: String) -> Single } diff --git a/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSourceImpl.swift b/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSourceImpl.swift index a3e044b3..c046fa91 100644 --- a/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSourceImpl.swift +++ b/Services/AuthService/Sources/Data/Remote/Datasource/RemoteAuthDataSourceImpl.swift @@ -18,6 +18,11 @@ class RemoteAuthDataSourceImpl: RemoteAuthDataSource { .asCompletable() } + func logout(accessToken: String) -> Completable { + self.provider.rx.request(.logout(accessToken: accessToken)) + .asCompletable() + } + func refreshToken(refreshToken: String) -> Single { self.provider.rx.request(.refreshToken(refreshToken: refreshToken)) .map(SigninAndRefreshTokenResponse.self) diff --git a/Services/AuthService/Sources/Data/Repository/AuthRepositoryImpl.swift b/Services/AuthService/Sources/Data/Repository/AuthRepositoryImpl.swift index cc8bf603..4aec7b36 100644 --- a/Services/AuthService/Sources/Data/Repository/AuthRepositoryImpl.swift +++ b/Services/AuthService/Sources/Data/Repository/AuthRepositoryImpl.swift @@ -90,11 +90,16 @@ class AuthRepositoryImpl: AuthRepository { } func logout() -> Completable { - Completable.create { completable in - self.localTokenDataSource.resetToken() - completable(.completed) - return Disposables.create() - } + guard let accessToken = try? fetchAccessToken() else { return Completable.empty() } + let observable = Completable.zip( + Completable.create { completable in + self.localTokenDataSource.resetToken() + completable(.completed) + return Disposables.create() + }, + self.remoteAuthDataSource.logout(accessToken: accessToken) + ) + return observable } }